COJN 0583 800602分蘋果

來源:互聯網
上載者:User

標籤:

 

800602分蘋果
難度層級:B; 已耗用時間限制:1000ms; Runspace限制:51200KB; 代碼長度限制:2000000B
試題描述
把M個同樣的蘋果放在N個同樣的盤子裡,允許有的盤子空著不放,問共有多少種不同的分法?(用K表示)5,1,1和1,5,1 是同一種分法。
輸入
第一行是測試資料的數目t,以下每行均包含二個整數M和N,以空格分開。
輸出
對輸入的每組資料M和N,用一行輸出相應的K。
輸入樣本
1
7 3
輸出樣本
8
其他說明
資料範圍:0<=t<=20,1<=M,N<=10。

題解:經典以0分dp。

 1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 #include<queue> 6 #include<cstring> 7 #define PAU putchar(‘ ‘) 8 #define ENT putchar(‘\n‘) 9 using namespace std;10 int fun(int m,int n){11     if(!m||n==1)return 1;12     if(n>m)return fun(m,m);13     else return fun(m,n-1)+fun(m-n,n);14 }15 inline int read(){16     int x=0,sig=1;char ch=getchar();17     for(;!isdigit(ch);ch=getchar())if(ch==‘-‘)sig=0;18     for(;isdigit(ch);ch=getchar())x=10*x+ch-‘0‘;19     return sig?x:-x;20 }21 inline void write(int x){22     if(x==0){putchar(‘0‘);return;}if(x<0)putchar(‘-‘),x=-x;23     int len=0,buf[15];while(x)buf[len++]=x%10,x/=10;24     for(int i=len-1;i>=0;i--)putchar(buf[i]+‘0‘);return;25 }26 void init(){27     int T=read();int m,n;28     while(T--){29         m=read();n=read();30         write(fun(m,n));ENT;31     }32     return;33 }34 void work(){35     return;36 }37 void print(){38     return;39 }40 int main(){init();work();print();return 0;}

 

COJN 0583 800602分蘋果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.