?
Problem Description There areNote that you cannot divide a whole cake into small pieces that is each cake must be complete in the
Input There are multiple test cases. The first line of input contains an integer
The first contains two integers
It is guaranteed that the total number of soda in the input doesn’t exceed 1000000. The number of test cases in the input doesn’t exceed 1000.
Output For each test case, output YES (without the quotes) if it is possible, otherwise output NO in the first line.
If it is possible, then output
Sample Input
4 1 2 5 3 5 2 9 3
Sample Output
NO YES 1 5 2 1 4 2 2 3 NO YES 3 1 5 9 3 2 6 7 3 3 4 8
?
?
/** hdu5355 思维+爆搜 题目大意:1~n这n个数分成m份,问是否能成功,若能请给出一种分配方式 解题思路:如果sum(1~n)%m!=0无解,并且sum/m#include #include #include #include using namespace std; typedef long long LL; vector vec[55]; LL n,m,dis,ans; int vis[105],pos[105],num[25]; bool dfs(int cnt,int sum,int id)///ans个数分成和相等的m份(id为第cnt份中最小的数,爆搜) { if(cnt==m+1)return true; for(int i=ans;i>=id;i--) { if(vis[i])continue; if(sum+i==dis) { pos[i]=cnt; vis[i]=1; if(dfs(cnt+1,0,1)) return true; vis[i]=0; return false; } else if(sum+i ans;i-=(2*m))///分成2*m份 { for(int j=1;j<=m;j++) { int x=i-j+1; int y=i-2*m+j; vec[j].push_back(x); vec[j].push_back(y); num[j]+=(x+y); } } dis=ave-num[1]; memset(vis,0,sizeof(vis)); memset(pos,0,sizeof(pos)); dfs(1,0,1); for(int i=1;i<=ans;i++) { vec[pos[i]].push_back(i); } for(int i=1;i<=m;i++) { printf(%d,vec[i].size()); for(int j=0;j ?
?