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) 我们发现对于一个限制 ...
随机推荐
- magento package
Magento Local module file is relative to app/code/local/ Magento Community module file is relative t ...
- 【转】java节省内存的几条建议
下面是参考网络资源总结的一些在Java编程中尽可能要做到的一些地方. 1. 尽量在合适的场合使用单例 使用单例可以减轻加载的负担,缩短加载的时间,提高加载的效率,但并不是所有地方都适用于单例,简单 ...
- iphone x 高度:100%; 兼容设置
问题: iphone x 会遇到页面设置 height:100%;之后但是底部还有一定的高度没有覆盖 解决方法: 1.让客户端设置webview的高度为100%; 2.html代码里面添加 viewp ...
- Failed to obtain lock on file /usr/local/nagios/var/ndo2db.lock: Permission denied : Permission denied
Failed to obtain lock on file /usr/local/nagios/var/ndo2db.lock: Permission denied : Permission den ...
- iOS逆向实战与工具使用(微信添加好友自动确认)
iOS逆向实战与工具使用(微信添加好友自动确认) 原文链接 源码地址 WeChatPlugin-iOS Mac OS 版微信小助手(远程控制.消息防撤回.自动回复.微信多开) 一.前言 本篇主要实现在 ...
- jacob的使用方法
网上一大堆你抄我的,我抄你的,但基本配置都没说清,做个笔记让后来的人少走冤枉路 1.下载最新的jacob,jdk版本一一对应,1.6对应jacob的1.16,1.7对应1.17.... 2.应用程序将 ...
- Oracle EXPDP and IMPDP
一.特点 • 可通过 DBMS_DATAPUMP 调用 • 可提供以下工具: – expdp – impdp – 基于 Web 的界面 • 提供四种数据移动方法: – 数据文件复制 – 直接路径 – ...
- UVALive 2238 Fixed Partition Memory Management 固定分区内存管理(KM算法,变形)
题意:目前有一部分可用内存,分为m个大小固定的区域.现有n个程序要执行,每个程序在不同大小的内存中运行所需的时间不同,要使运行完所有程序所耗时最少,问每个程序在哪块区域中从什么时间运行到什么时间,以及 ...
- df - 报告文件系统磁盘空间的使用情况
总览 df [OPTION]... [FILE]... POSIX 选项: [-kP] GNU 选项 (最短方式): [-ahHiklmPv] [-t fstype] [-x fstype] [--b ...
- 自己写的画loss曲线代码
import matplotlib.pyplot as plt iteration = [] loss = [] with open('/home/sensetime/log.txt','r') as ...