xtu read problem training A - Dividing
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
Description
Input
The last line of the input file will be "0 0 0 0 0 0"; do not process this line.
Output
Output a blank line after each test case.
Sample Input
1 0 1 2 0 0
1 0 0 0 1 1
0 0 0 0 0 0
Sample Output
Collection #1:
Can't be divided. Collection #2:
Can be divided. 解题:多重背包的二进制优化,第一次搞二进制优化啊。。。。。。无尽的WA
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
int dp[],w[] = {,,,,,,};
int num[],sum,val;
int main() {
int i,j,k,ks = ,temp,u;
int a[];
while(true) {
for(val = sum = ,i = ; i <= ; i++) {
scanf("%d",num+i);
sum += num[i];
val += i*num[i];
}
if(!sum) break;
printf("Collection #%d:\n",ks++);
if(val&) puts("Can't be divided.");
else {
temp = val>>;
memset(dp,,sizeof(dp));
for(i = ; i <= ; i++) {
int u = log2(num[i]);
for(k = ; k <= u; k++){
if(k == u){a[k] = num[i]-(<<u)+;}
else a[k] = <<k;
}
for(k = ; k <= u; k++){
for(j = temp; j >= a[k]*i; j--){
dp[j] = max(dp[j],dp[j-a[k]*i]+a[k]*i);
}
}
}
if(dp[temp] == temp) puts("Can be divided.");
else puts("Can't be divided.");
}
printf("\n");
}
return ;
}
xtu read problem training A - Dividing的更多相关文章
- xtu read problem training 3 B - Gears
Gears Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 3789 ...
- xtu read problem training 3 A - The Child and Homework
The Child and Homework Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on Code ...
- xtu read problem training 2 B - In 7-bit
In 7-bit Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 3 ...
- xtu read problem training 4 A - Moving Tables
Moving Tables Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ...
- xtu read problem training 4 B - Multiplication Puzzle
Multiplication Puzzle Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. O ...
- xtu read problem training B - Tour
B - Tour Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descriptio ...
- [LeetCode&Python] Problem 728. Self Dividing Numbers
A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is ...
- 【Leetcode_easy】728. Self Dividing Numbers
problem 728. Self Dividing Numbers solution1: 使用string类型来表示每位上的数字: class Solution { public: vector&l ...
- Codeforces 380 简要题解
ABC见上一篇. 感觉这场比赛很有数学气息. D: 显然必须要贴着之前的人坐下. 首先考虑没有限制的方案数.就是2n - 1(我们把1固定,其他的都只有两种方案,放完后长度为n) 我们发现对于一个限制 ...
随机推荐
- 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
- 1-2JDK的安装和环境变量设置
JDK的下载和安装 可以去oracle官网里面下载JDK:http://www.oracle.com 英文不好的同学可以通过下面这个百度网盘的链接进行下载:http://pan.baidu.com/s ...
- Java中“==”的使用,以及“==”和equal的比较
int i02=59 ,这是一个基本类型,存储在栈中. Integer i03 =Integer.valueOf(59); 因为 IntegerCache 中已经存在此对象,所以,直接返回引用. In ...
- Java 学习列表
这是从450家企业的招聘信息中统计而来,相对来说还是比较真实的,虽然有些公司的招聘要求万年不变,但还是可以大致反应企业的招聘要求的.
- 基于Java实现的冒泡排序算法
冒泡排序是一种简单基础的排序算法,相信在大学课堂里老师已经讲过了,现在我基于Java来实现一遍. 简述 冒泡排序正如其关键词一样,杂乱的气泡经过浮动,最后大的气泡飘到了上面而小的气泡在下面,无序的元素 ...
- void运算符
void是一元运算符,它出现在操作数之前,操作数可以是任意类型,操作数会照常计算,但忽略计算结果并返回undefined.由于void会忽略操作数的值,因此在操作数具有副作用的时候使用void来让程序 ...
- Selenium私房菜系列3 -- Selenium API参考手册【ZZ】
大家在编写测试案例想查阅Selenium API说明时,可以查阅本文,否则请跳过! (注:这里API版本比较老,新版本的Selenium的API在这里不一定能找到.) Selenium API说明文档 ...
- Elasticsearch 插入地理索引文档一直为空
今天在获取插入索引数据的时候,一直提示插入不成功,尝试了很多方法,原来是因为在插入的时候应该先 插入Latitude后插入longitude修改后的代码如下 public boolean insert ...
- 在云环境上使用SLF4J对Java程序进行日志记录
我开发了一个Java应用,部署到云环境上之后,用postman测试发现不能按照我期望的工作,但是返回的消息对我没有任何帮助. 因为部署在云端的应用很难像本地Java应用一样调试,所以我打算用SLF4J ...
- 前端基础入门第一阶段-Web前端开发基础环境配置
Web前端和全栈的定义: A.什么是传统传统web前端:需要把设计师的设计稿,切完图,写标签和样式,实现JS的效果,简而言之即只需要掌握HTML的页面结构,CSS的页面样式,javaScript页面的 ...