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 |
Re:请问:怎么递归啊?In Reply To:Re:请问:怎么递归啊? Posted by:zsukingdom at 2004-06-05 00:24:01 #include <iostream.h> int total=0; int a[11]={0}; void work(int m,int n,int dep) { int i,v; if (dep==n) total++; else { v=n-dep+1; for (i=a[dep-1];i<=m/v;i++) { a[dep]=i; work(m-i,n,dep+1); } } } int main() { int t,m,n; cin>>t; while (t>0) { a[0]=1; cin>>m>>n; while (n>0) { work(m,n,1); n--; } cout<<total<<endl; total=0; t--; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator