10313 - Pay the Price

来源:互联网 发布:妖精的口袋淘宝 编辑:程序博客网 时间:2024/05/01 00:28
描述:要用到Ferrers图算法,看了一下似懂非懂,通过别人的代码,也似乎看懂了#include <cstdio>#include <cstring>long long v[310][310]= {{0}};void dp(){    v[0][0]=1;    for(int i=0; i<=300; i++)        for(int j=1; j<=300; j++)        {            if(i>=j) v[i][j]+=v[i-j][j];            v[i][j]+=v[i][j-1];        }}int main(){  //  freopen("a.txt","r",stdin);    dp();    int n,m,k,flag;    char s[110];    while(gets(s))    {        m=k=flag=-1;        sscanf(s,"%d%d%d",&n,&m,&k);        if(m>300) m=300;        if(k>300) k=300;        if(m==-1) printf("%lld\n",v[n][n]);        else if(k==-1) printf("%lld\n",v[n][m]);        else        {            if(m>=1) printf("%lld\n",v[n][k]-v[n][m-1]);            else printf("%lld\n",v[n][k]);        }    }    return 0;}