Rokua P2386 put the apples

Source: Internet
Author: User

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&LT;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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.