博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LA4794 分享巧克力
阅读量:4323 次
发布时间:2019-06-06

本文共 2882 字,大约阅读时间需要 9 分钟。

Sharing Chocolate

Chocolate in its many forms is enjoyed by millions of people around the world every day. It is a truly universal candy available in virtually every country around the world.

You find that the only thing better than eating chocolate is to share it with friends. Unfortunately your friends are very picky and have different appetites: some would like more and others less of the chocolate that you offer them. You have found it increasingly difficult to determine whether their demands can be met. It is time to writte a program that solves the problem once and for all!

Your chocolate comes as a rectangular bar. The bar consists of same-sized rectangular pieces. To share the chocolate you may break one bar into two pieces along a division between rows or columns of the bar. You or the may then repeatedly break the resulting pieces in the same manner. Each of your friends insists on a getting a single rectangular portion of the chocolate that has a specified number of pieces. You are a little bit insistent as well: you will break up your bar only if all of it can be distributed to your friends, with none left over.

For exampla, Figure 9 shows one way that a chocolate bar consisting of 3 x 4 pieces can be split into 4 parts that contain 6, 3, 2, and 1 pieces respectively, by breanking it 3 times (This corresponds to the first sample input.)

Input 

The input consists of multiple test cases each describing a chocolate bar to share. Each description starts with a line containing a single integer n (1<=n<=15), the number of parts in which the bar is supposed to be split. This is followed by a line containing two integers x and y(1<=xy<=100), the dimensions of the chocolate bar. The next line contains n positive integers, giving the number of pieces that are supposed to be in each of the n parts.

The input is terminated by a line containing the integer zero.

Output 

For each test case, first display its case number. Then display whether it is possible to break the chocolate in the desired way: display ``Yes" if it is possible, and ``No" otherwise. Follow the format of the sample output.

Sample Input 

4  3 4  6 3 2 1  2  2 3  1 5 0

Sample Output 

Case 1: Yes Case 2: No 题意: 将一个x*y大小的巧克力分成n分, 固定大小a[i], 判断是否可以成功. 解题思路: 1. 设状态dp[x][y][S]: x*y的巧克力是否可以分割成集合S. 2. dp[x][y][S]=true 当且仅当:   dp[x0][y][S0] = dp[x-x0][y][S-S0] = true  //1<=x0
dp[x][S]=true 当且仅当:  
    sum[S0]%x==0 AND dp[min(x,sum[S]/x)][S0] = dp[min(x,sum[S]/x)][S-S0] = true 或者是  sum[S0]%y==0 AND dp[min(y,sum[S]/y)][S0] = dp[min(y,sum[S]/y)][S-S0] = true
6.输入之后要比较所有所有a[i]的和是否等于x*y 代码如下:
#include
#include
#define Max_n 15#define Size 105using namespace std;bool d[Size][(1<
>x>>y; for(int i=0;i
>a[i]; } for(int S=0;S<(1<

 

转载于:https://www.cnblogs.com/FuTaimeng/p/5422557.html

你可能感兴趣的文章
tftp 开发板ping不通PC机
查看>>
未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”
查看>>
Erdos
查看>>
docker初学
查看>>
面向对象的程序第三次实验作业
查看>>
Windows 安装启动apache时出现错误的解决方法
查看>>
Object.prototype.toString()
查看>>
int.Parse()与int.TryParse()
查看>>
c#调用钩子
查看>>
最近最少使用队列算法
查看>>
ONOS:负载均衡路由算法及应用开发(二)
查看>>
把js写到链接a标签的href中和写到onclick中的区别
查看>>
压缩解压缩命令
查看>>
MySQL基于binlog主从复制
查看>>
HDU 1394(归并求逆序对)
查看>>
配置 Windows 下的 nodejs C++ 模块编译环境 安装 node-gyp
查看>>
我和Socket的第一次亲密接触
查看>>
2016/09/22
查看>>
2016/09/02
查看>>
项目中遇到的Redis缓存问题
查看>>