666:放蘋果

來源:互聯網
上載者:User

標籤:names   return   nbsp   int   ret   pac   space   資料   允許   

描述把M個同樣的蘋果放在N個同樣的盤子裡,允許有的盤子空著不放,問共有多少種不同的分法?(用K表示)5,1,1和1,5,1 是同一種分法。輸入第一行是測試資料的數目t(0 <= t <= 20)。以下每行均包含二個整數M和N,以空格分開。1<=M,N<=10。輸出對輸入的每組資料M和N,用一行輸出相應的K。範例輸入

17 3

範例輸出

8

來源[email protected]

 1 #include<cstdio> 2 using namespace std; 3 int  f(int m,int n) 4 { 5     if(n==1||m==0) return 1;  6     if(n>m)return f(m,m); 7     return f(m,n-1)+f(m-n,n); 8 } 9 10 int main()11 {12     int num;13     scanf("%d",&num);14     while(num--)15     {16         int m,n;17         scanf("%d%d",&m,&n);18         printf("%d\n",f(m,n));19     }20 21     return 0;22 }

 

666:放蘋果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.