Problem Description
There are m soda
and today is their birthday. The 1-st
soda has prepared n cakes
with size 1,2,…,n.
Now 1-st
soda wants to divide the cakes into m parts
so that the total size of each part is equal. 



Note that you cannot divide a whole cake into small pieces that is each cake must be complete in the m parts.
Each cake must belong to exact one of m parts.
 
Input
There are multiple test cases. The first line of input contains an integer T,
indicating the number of test cases. For each test case:



The first contains two integers n and m (1≤n≤105,2≤m≤10),
the number of cakes and the number of soda.

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 m lines
denoting the m parts.
The first number si of i-th
line is the number of cakes in i-th
part. Then si numbers
follow denoting the size of cakes in i-th
part. If there are multiple solutions, print any of them.
 
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 这题和木棒拼接正方形非常像,用同样的思路即可了。 这里注意dfs可能比較深,所以要手动开栈。#pragma comment(linker, "/STACK:102400000,102400000") 这句话加在程序最前面。
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define maxn 100050
#define ll long long
int vis[maxn],liang,fen,n;
set<int>myset[20];
set<int>::iterator it; int dfs(int x,int pos,ll len)
{
int i;
if(x==fen)return 1;
for(i=pos;i>=1;i--){
if(!vis[i]){
vis[i]=1;
if(len+i<liang){
myset[x].insert(i);
if(dfs(x,i-1,len+i))return 1;
myset[x].erase(i);
}
else if(len+i==liang){
myset[x].insert(i);
if(dfs(x+1,n,0))return 1;
myset[x].insert(i);
}
vis[i]=0;
}
}
return 0;
} int main()
{
int i,j,T;
ll num;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&fen);
num=(ll)(n+1)*n/2;
if(n<fen || num%fen!=0 || num/fen<n){
printf("NO\n");continue;
}
liang=num/fen;
memset(vis,0,sizeof(vis));
for(i=0;i<=fen;i++){
myset[i].clear();
} if(dfs(0,n,0)){
printf("YES\n");
for(i=0;i<fen;i++){
printf("%d",myset[i].size());
for(it=myset[i].begin();it!=myset[i].end();it++){
printf(" %d",*it);
}
printf("\n");
}
}
else printf("NO\n");
}
return 0;
}
/*
100
50 10
NO
40 10
YES
3 3 39 40
3 7 37 38
3 11 35 36
3 15 33 34
3 19 31 32
3 23 29 30
4 1 26 27 28
5 2 9 22 24 25
5 6 17 18 20 21
8 4 5 8 10 12 13 14 16
*/

hdu5355 Cake的更多相关文章

  1. hdu5355 Cake(构造)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Cake Time Limit: 2000/1000 MS (Java/Other ...

  2. hdu5355 思维+爆搜

    pid=5355">http://acm.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m sod ...

  3. Windows 7上执行Cake 报错原因是Powershell 版本问题

    在Windows 7 SP1 电脑上执行Cake的的例子 http://cakebuild.net/docs/tutorials/getting-started ,运行./Build.ps1 报下面的 ...

  4. 2015暑假多校联合---Cake(深搜)

    题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...

  5. Scalaz(15)- Monad:依赖注入-Reader besides Cake

    我们可以用Monad Reader来实现依赖注入(dependency injection DI or IOC)功能.Scala界中比较常用的不附加任何Framework的依赖注入方式可以说是Cake ...

  6. uva10167 Birthday Cake

    Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them. Now we put t ...

  7. HDU 4762 Cut the Cake(公式)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  8. Brute Force --- UVA 10167: Birthday Cake

     Problem G. Birthday Cake  Problem's Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudg ...

  9. 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest, B. Layer Cake

    Description Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping ...

随机推荐

  1. BZOJ 4698 差分+后缀数组

    思路: 对所有序列差分一下 公共串的长度+1就是答案了 二分 扫一遍height即可,.. //By SiriusRen #include <cstdio> #include <cs ...

  2. c++ 虚函数,纯虚函数的本质区别

    转载博客:https://mp.weixin.qq.com/s?__biz=MzAxNzYzMTU0Ng==&mid=2651289202&idx=1&sn=431ffd1fa ...

  3. mysqlslap对mysql进行压力测试

    mysqlslap是从5.1.4版开始的一个MySQL官方提供的压力测试工具.通过模拟多个并发客户端访问MySQL来执行压力测试,并且能很好的对比多个存储引擎在相同环境下的并发压力性能差别. mysq ...

  4. QS之force(2)

    Examples 1) Force input1 to 0 at the current simulator time. force input1 0 2) Force the fourth elem ...

  5. Equals相關的一些要點

    什麽時候需要覆蓋Equals? 自定義的值類型需要覆蓋,因爲框架默認的實現是基於反射的,效率不高. 自定義的引用類型要根據業務需要來決定是否提供覆蓋.    什麽時候需要覆蓋operator==()? ...

  6. Cache-Control官方文档

    https://tools.ietf.org/html/draft-ietf-httpbis-p6-cache-25#page-21 5.2. Cache-Control The "Cach ...

  7. Ubuntu 16.04安装和卸载软件命令

    安装软件 apt-get install softname1 softname2 softname3…… 卸载软件 apt-get remove softname1 softname2 softnam ...

  8. Bem命名

    BEM思想 1. 什么是BEM: BEM:(Block块,Element元素,Modifier修饰符)一种命名规范, 其核心思想是将页面拆分成一个个独立的富有语义的块(blocks),从而使得团队在开 ...

  9. BZOJ 1426: 收集邮票 数学期望 + DP

    Description 有n种不同的邮票,皮皮想收集所有种类的邮票.唯一的收集方法是到同学凡凡那里购买,每次只能买一张,并且 买到的邮票究竟是n种邮票中的哪一种是等概率的,概率均为1/n.但是由于凡凡 ...

  10. 前端开发—HTML

    HTML介绍 web服务的本质 import socket sk = socket.socket() sk.bind(("127.0.0.1", 8080)) sk.listen( ...