PROBLEM F: 切煎饼

http://www.yyycode.cn/index.php/2020/06/05/problem-f-%e5%88%87%e7%85%8e%e9%a5%bc/


Description

王小二自夸刀工不错,有人放一张大的圆煎饼在砧板上,问他:饼不允许离开砧板,切100刀最多能切多少块?

Input

多组测试数据,每组输入1个整数,代表切的刀数

Output

每组输出1个整数,为最多能切的块数

Sample Input

1
2
3

Sample Output

2
4
7

HINT


思路:当前切的第n条能和已有的n-1条线产生n-1个交点,然后多出n-1+1个区域。从而dp

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1e5;
typedef long long LL;
LL a[maxn];
int main(void)
{
    a[1]=2;a[2]=4;a[3]=7;
    for(LL i=4;i<=1000;i++)
        a[i]=a[i-1]+i-1+1;
    LL t;
    while(cin>>t)
    {
        cout<<a[t]<<endl;
    }
 
return 0;
}

猜你喜欢

转载自blog.csdn.net/zstuyyyyccccbbbb/article/details/106580350