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<iostream> using namespace std; int n,m; int a[11]; void dfs(int cur, int &k) { if(cur>n)return ; k++; int ll=a[cur]; for(int m=a[cur-1]; m<=ll/2; m++) { a[cur]=m; a[cur+1]=ll-m; dfs(cur+1,k); } a[cur]=0; } int main() { int t; cin>>t; while(t--) { cin>>m>>n; int k=0; memset(a,0,sizeof a); a[0]=1; a[1]=m; dfs(1,k); cout<<k<<endl; } system("pause"); return 0; } 那个递归的方法哥想不出来 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator