P2386 put an appleTopic Background
(poj1664)
Title Description
Put the M-same Apple on n the same plate, allow the plates to be empty, and ask how many different distributions (5,1,1 and 1,1,5 are the same method)
input/output formatInput Format:
The first line is the number of test data t (0 <= T <= 20), each of the following lines consists of two integers m and n, separated by a space. 1<=m,n<=10
output Format:
For each set of data entered M and N, the corresponding k is output in one line.
input/Output sampleInput Sample # #: Copy
17 3
Output Example # #: Replication
8
Input Example #: Copy
17 3
Output Example # #: Copy
8
Positive solution thinking: Dynamic programming.
F[I][J] said that after I put out the first Apple, there is a J plate is not empty, how many kinds of solutions.
#include <map>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespaceStd;map<string,int>Vis;intT,n,m,ans;intnum[ One],bns[ One];voidDfsintx) { if(x==N) { for(intI=1; i<=m;i++) num[i]=Bns[i]; Sort (num+1, num+1+M);strings; for(intI=1; i<=m;i++) s+=Char(num[i]+'0'); if(!vis[s]) {ans++,vis[s]=1; } return ; } for(intI=1; i<=m;i++) {Bns[i]+=1; DFS (x+1); Bns[i]-=1; }}intMain () {scanf ("%d",&t); while(t--) {scanf ("%d%d",&n,&m); Ans=0;d FS (0); cout<<ans<<Endl; }}
10 points violence Code
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;intT,n,k,ans;intdp[ +][ +];intMain () {scanf ("%d",&t); while(t--) {scanf ("%d%d",&n,&k); dp[0][0]=dp[1][1]=1; for(intI=1; i<=n;i++) for(intj=1; j<=k;j++){ if(I<J) {dp[i][j]=0;Continue; } DP[I][J]=max (dp[i-j][j]+dp[i-1][j-1],dp[i][j]); } for(intI=1; i<=k;i++) ans+=Dp[n][i]; cout<<ans<<endl;ans=0; Memset (DP,0,sizeof(DP)); }}
Rokua P2386 put the apples