SDAU 课程练习3 1021
来源:互联网 发布:网络教育大学有哪些 编辑:程序博客网 时间:2024/05/29 19:29
Problem U
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 7 Accepted Submission(s) : 2
Problem Description
Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could just split the collection in half. But unfortunately, some of the marbles are larger, or more beautiful than others. So, Marsha and Bill start by assigning a value, a natural number between one and six, to each marble. Now they want to divide the marbles so that each of them gets the same total value. <br>Unfortunately, they realize that it might be impossible to divide the marbles in this way (even if the total value of all marbles is even). For example, if there are one marble of value 1, one of value 3 and two of value 4, then they cannot be split into sets of equal value. So, they ask you to write a program that checks whether there is a fair partition of the marbles.<br>
Input
Each line in the input describes one collection of marbles to be divided. The lines consist of six non-negative integers n1, n2, ..., n6, where ni is the number of marbles of value i. So, the example from above would be described by the input-line ``1 0 1 2 0 0''. The maximum total number of marbles will be 20000. <br><br>The last line of the input file will be ``0 0 0 0 0 0''; do not process this line.<br>
Output
For each colletcion, output ``Collection #k:'', where k is the number of the test case, and then either ``Can be divided.'' or ``Can't be divided.''. <br><br>Output a blank line after each test case.<br>
Sample Input
1 0 1 2 0 01 0 0 0 1 10 0 0 0 0 0
Sample Output
Collection #1:Can't be divided.Collection #2:Can be divided.
题目大意:
六个价值的小弹珠,给出数量,问是否可以平分价值。
思路:
也是完全背包,不用多想,定义好状态后,模板就行啦。同样的,0 1 超时。
感想:
好烦啊。。。
AC代码:
#include <stdio.h>#include<iostream>#include<cstdio>#include<string.h>#include<algorithm>using namespace std;int val[10005];int w[10005];int dp[100005];int v,k;void ZeroOnePack(int cost,int weight)//cost 为费用, weight 为价值{ for(int i=v;i>=cost;i--) if(dp[i-cost]+weight>dp[i]) dp[i]=dp[i-cost]+weight;}void CompletePack(int cost,int weight){ for(int i=cost;i<=v;i++) if(dp[i-cost]+weight>dp[i]) dp[i]=dp[i-cost]+weight;}void MultiplePack(int cost ,int weight,int amount){ if(cost*amount>=v) CompletePack(cost,weight); else { for(int k=1;k<amount;) { ZeroOnePack(k*cost,k*weight); amount-=k; k<<=1; } ZeroOnePack(amount*cost,amount*weight); }}int main(){ int n,i,j,k,vv,dd; int T,V,V1,V2,sumv; //freopen("r.txt","r",stdin); int casee=0; while(666) { casee++; v=0; for(i=1;i<=6;i++) { ~scanf("%d",&val[i]); v+=val[i]*i; } if(v==0) break; if(v%2) { cout<<"Collection #"<<casee<<":"<<endl; cout<<"Can't be divided."<<endl; cout<<endl; continue; } v=v/2; memset(dp,0,sizeof(dp)); for(i=1;i<=6;i++) { MultiplePack(i,i,val[i]); } cout<<"Collection #"<<casee<<":"<<endl; if(dp[v]==v) cout<<"Can be divided."<<endl; else cout<<"Can't be divided."<<endl; cout<<endl; } return 0;}
0 0
- SDAU 课程练习3 1021
- SDAU 课程练习3 1001
- SDAU 课程练习3 1002
- SDAU 课程练习3 1003
- SDAU 课程练习3 1004
- SDAU 课程练习3 1005
- SDAU 课程练习3 1008
- SDAU 课程练习3 1009
- SDAU 课程练习3 1014
- SDAU 课程练习3 1015
- SDAU 课程练习3 1016
- SDAU 课程练习3 1017
- SDAU 课程练习3 1018
- SDAU 课程练习3 1019
- SDAU 课程练习3 1020
- SDAU 课程练习3 1023
- SDAU 课程练习3 1024
- SDAU 课程练习3 递推大汇总
- USB hub 分线器设计
- pyqt4 绘制点,椭圆,线,矩形
- ubuntu 源码安装 screen
- 第十周项目一 阅读下面的定义,请说出在测试函数中不同情况的调用产生的结果(5 d)
- 通过自定义Filter(适配器),并实现浏览器的禁止缓存的Filter
- SDAU 课程练习3 1021
- 大声的喊——NOI2016,我来了!
- Python制作统计图形
- ThinkPHP Seesion的Memcached驱动支持阿里云OCS及集群
- Lecture 2 - Simple Word Vector representations: word2vec, GloVe
- 如何用拼接的字符串调用javascript的变量或方法
- Leetcode题解14 20. Valid Parentheses
- Eclipse导入MyEclipse工程(web项目显示为java项目解决办法)
- Android Design Support Library--使用CoordinatorLayout来处理滚动