王小二切饼

来源:互联网 发布:阴谋论书籍 知乎 编辑:程序博客网 时间:2024/06/05 19:58
Problem Description

王小二自夸刀工不错,有人放一张大的煎饼在砧板上,问他:“饼不许离开砧板,切n(1<=n<=100)刀最多能分成多少块?”
Input

输入切的刀数n。
Output

输出为切n刀最多切的饼的块数。
Example Input

100
Example Output

5051


不切是 1

切一刀是2    f(0)+1

切2刀是 4    f(0)+2

切n刀是     f(n-1)+n



#include<stdio.h>int f(int n)    {        int a[101];        a[0] = 1;        for(int i=1;i<=n;i++)        {            a[i] = a[i-1]+i;        }        return a[n];    }int main(){    int n;    while(~scanf("%d",&n)&&n)    {        printf("%d\n",f(n));    }}