Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
递归或者DFS都可以,就贴一个DFS吧#include <iostream> #include <string> using namespace std; int t,n,m,s; int num[11]; void dfs(int x,int y) { if(x==m) { if(y>=num[m-1]) s++; } else { for(int i=num[x-1];i<=y&&(y/(m-x)>=i);i++) { num[x]=i; dfs(x+1,y-i); } } } int main() { scanf("%d",&t); while(t--) { memset(num,0,sizeof(num)); scanf("%d%d",&n,&m); s=0; dfs(1,n); printf("%d\n",s); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator