DP-遞推-POJ-1664-放蘋果

#include<cstdio>
#include<cctype>
#include<cstring>
#define mem(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
const ll maxn=1e5+10;
const ll mod=1e9+7;
const ll inf=0x7f7f7f7f;
template<typename T>void read(T &x)
{
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T>void write(T x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
ll T;
bool flag;
ll dp[20][20];
ll m,n;
int main()
{
    dp[0][0]=1;
    for(int i=0;i<=15;i++)
    {
        for(int j=1;j<=15;j++)
        {
            if(j>i)
            {
                dp[i][j]=dp[i][i];
            }
            else
            {
                dp[i][j]=dp[i][j-1]+dp[i-j][j];
            }
        }
    }
    read(T);
    while(T--)
    {
        read(m);
        read(n);
        printf("%lld\n",dp[m][n]);
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章