Light oj 1233 - Coin Change (III) (背包优化)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1233
题目就不说明了。
背包的二进制优化,比如10可以表示为1 2 4 3,而这些数能表示1 ~ 10的任意的数。然后类似01背包就好了。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <ctime>
#include <queue>
#include <list>
#include <set>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
const int N = 1e5 + ;
int dp[N];
int val[], c[]; int main()
{
int t, n, m;
scanf("%d", &t);
for(int ca = ; ca <= t; ++ca) {
scanf("%d %d", &n, &m);
for(int i = ; i <= n; ++i) {
scanf("%d", val + i);
}
for(int i = ; i <= n; ++i) {
scanf("%d", c + i);
}
memset(dp, , sizeof(dp));
dp[] = ;
for(int i = ; i <= n; ++i) {
for(int k = ; k <= c[i]; k <<= ) {
for(int j = m; j >= k*val[i]; --j) {
dp[j] |= dp[j - k*val[i]];
}
c[i] -= k;
}
if(c[i]) {
for(int j = m; j >= c[i]*val[i]; --j) {
dp[j] |= dp[j - c[i]*val[i]];
}
}
}
int ans = ;
for(int i = ; i <= m; ++i) {
ans += dp[i];
}
printf("Case %d: %d\n", ca, ans);
}
return ;
}
Light oj 1233 - Coin Change (III) (背包优化)的更多相关文章
- C - Coin Change (III)(多重背包 二进制优化)
C - Coin Change (III) Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- LeetCode OJ 322. Coin Change DP求解
题目链接:https://leetcode.com/problems/coin-change/ 322. Coin Change My Submissions Question Total Accep ...
- Light oj 1138 - Trailing Zeroes (III) 【二分查找 && N!中末尾连续0的个数】
1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...
- uva674 Coin Change ——完全背包
link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- light oj 1138 - Trailing Zeroes (III)【规律&&二分】
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- Light oj 1138 - Trailing Zeroes (III) 【二分查找好题】【 给出N!末尾有连续的Q个0,让你求最小的N】
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...
- Light oj 1138 - Trailing Zeroes (III) (二分)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...
- Light OJ Dynamic Programming
免费做一样新 1004 - Monkey Banana Problem 号码塔 1005 - Rooks 排列 1013 - Love Calculator LCS变形 dp[i][j][k]对于第一 ...
- UVA.674 Coin Change (DP 完全背包)
UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...
随机推荐
- 定时任务之crond服务
计划任务分为一次性计划任务与长期性计划任务 一次性计划任务:今天11:25执行重启网卡操作,执行结束 即任务消失 一次性计划任务格式: 创建:"at 时间" #默认采用的是交互式 ...
- Codeforces 664D Graph Coloring 二分图染色
题意: 一个无向图的每条边为红色或蓝色,有这样一种操作:每次选一个点,使与其相邻的所有边的颜色翻转. 求解是否可以经过一系列操作使所有的边颜色相同,并输出最少操作次数和相应的点. 分析: 每个点要么选 ...
- jar包导入仓库中
mvn install:install-file -Dfile=F:/kaptcha-2.3.jar -DgroupId=com.google.code.kaptcha -DartifactId=ka ...
- IOS开发---菜鸟学习之路--(二十四)-iOS7View被导航栏遮挡问题的解决
(此文为复制帖,原文地址为:http://blog.sina.com.cn/s/blog_a8192bdd0101af40.html) self.navigationController.naviga ...
- chrome浏览器设置自动切换代理上网的方法
利用shadowsocks代理软件实现FQ时,如果都走代理模式,流量肯定不够.可以利用chrome的SwitchyOmega插件实现自动根据URL来决定是否使用代理.设置如下: 1.安装Switchy ...
- Python+Selenium练习篇之6-利用class name定位元素
有时候,我们在用firepath(不会的请点这里)查看元素的XPath信息,发现没有可以用来定位的id信息,这个时候我们就需要考虑用其他的可用的来定位元素.本文介绍如何通过元素节点中class nam ...
- python-day4-内置函数2
摘要:python中有好多可用性特别强的内置函数,熟练掌握对于以后的编程过程中有很大的帮助~~~~ callable函数.chr函数与ord函数.random函数.compile函数.evec与eva ...
- Leetcode 514.自由之路
自由之路 视频游戏"辐射4"中,任务"通向自由"要求玩家到达名为"Freedom Trail Ring"的金属表盘,并使用表盘拼写特定关键词 ...
- [ecmagnet][python基础]有关git那些事
#1 git教程 # 注册git服务器用户,权限-- 注意这个和客户端用户不是一样 # 客户端(linux)提交代码到本地仓库(简单版,了解原理) a.安装git sudo apt-get insta ...
- VMSAv8-64 translation table format descriptors
通常情况下,一个 descriptor 可能是以下的几种 entry: 非法或者异常的 entry. Table entry, 指向 next-level translation table. Blo ...