标签:des style color io os ar for sp div
Let us consider sets of positive integers less than or equal to n. Note that all elements of a set are0
DP递推:dp[i][k][s]表示个数递推关系:dp[i][k][s]=dp[i-1][k][s]+dp[i-1][k-1][s-i].
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1000+100;
int dp[21][11][156];
void init()
{
memset(dp,0,sizeof(dp));
dp[1][1][1]=1;
for(int i=1;i<=20;i++)
{
dp[i][1][i]=1;
dp[i][0][0]=1;
}
for(int i=2;i<=20;i++)
{
for(int k=1;k<=10;k++)
{
if(k>i) continue;
for(int s=1;s<=155;s++)
{
int sum=0;
// for(int j=1;j<i&&j<=k;j++)
sum+=dp[i-1][k][s];
if(s>=i) sum+=dp[i-1][k-1][s-i];
dp[i][k][s]=sum;
// if(i<=4&&s<10)
// cout<<i<<" "<<k<<" "<<s<<" "<<sum<<endl;
}
}
}
// cout<<dp[4][2][5]<<endl;
}
int main()
{
init();
int n,k,s;
while(~scanf("%d%d%d",&n,&k,&s)&&(n+k+s))
printf("%d\n",dp[n][k][s]);
return 0;
}
3 1 3 4 2 4
1 2
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
typedef long long LL;
using namespace std;
LL dp[201][201][22][2];
void init()
{
memset(dp,0,sizeof(dp));
dp[1][0][1][0]=1;
dp[1][1][1][1]=1;
for(int i=1;i<=200;i++)
{
dp[i][0][1][0]=1;
dp[i][i][1][1]=1;
}
for(int i=2;i<=200;i++)
{
for(int j=1;j<=i;j++)
{
for(int k=1;k<=20&&k<=i;k++)
{
dp[i][j][k][0]=dp[i-1][j][k-1][1]+dp[i-1][j][k][0];
dp[i][j][k][1]=dp[i-1][j-1][k][1]+dp[i-1][j-1][k-1][0];
}
}
}
// cout<<dp[12][13][15][0]<<endl;
}
int main()
{
int n,m,k;
init();
while(~scanf("%d%d%d",&n,&m,&k))
printf("%I64d\n",dp[n][m][k][0]+dp[n][m][k][1]);
return 0;
}
标签:des style color io os ar for sp div
原文地址:http://blog.csdn.net/u013582254/article/details/39564351