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:递归或者DFS都可以,就贴一个DFS吧In Reply To:递归或者DFS都可以,就贴一个DFS吧 Posted by:husanfeng at 2012-11-24 10:09:41 > #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; > } dfs如何保证不重复? Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator