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 |
递归算法!!!附代码!#include "stdio.h" int n,m,a[12],sum; void dfs(int deep,int total) { int i; if(deep>m+1) return; if(total==n&&deep==m+1) { sum++; return; } for(i=0;i<=n;i++) { a[deep]=i; if(a[deep]>=a[deep-1]) dfs(deep+1,total+a[deep]); } } int main() { int cases; scanf("%d",&cases); while(cases--) { scanf("%d %d",&n,&m); sum=0; dfs(1,0); printf("%d\n",sum); } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator