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(i,p,j) //i:放苹果的位置, //p:第i个位置放的苹果的个数,用来做后面的最底限,以构造‘非降’序列 //还剩了j个苹果可以放 #include<iostream> using namespace std; int n,m,ans; void dfs(int i,int p,int j) { int k; if(i==m-1) { ans++; return; } for(k=p;2*k<=j;k++)//“2*k<=j”这个地方弄了不少时间,k<=j-k才是不降序列 dfs(i+1,k,j-k); } int main() { int t; cin>>t; while(t--) { ans=0; cin>>n>>m; dfs(0,0,n); cout<<ans<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator