题目链接: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) (背包优化)的更多相关文章

  1. C - Coin Change (III)(多重背包 二进制优化)

    C - Coin Change (III) Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  2. LeetCode OJ 322. Coin Change DP求解

    题目链接:https://leetcode.com/problems/coin-change/ 322. Coin Change My Submissions Question Total Accep ...

  3. Light oj 1138 - Trailing Zeroes (III) 【二分查找 &amp;&amp; N!中末尾连续0的个数】

    1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...

  4. uva674 Coin Change ——完全背包

    link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  5. light oj 1138 - Trailing Zeroes (III)【规律&&二分】

    1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit:  ...

  6. 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 ...

  7. Light oj 1138 - Trailing Zeroes (III) (二分)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...

  8. Light OJ Dynamic Programming

    免费做一样新 1004 - Monkey Banana Problem 号码塔 1005 - Rooks 排列 1013 - Love Calculator LCS变形 dp[i][j][k]对于第一 ...

  9. UVA.674 Coin Change (DP 完全背包)

    UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...

随机推荐

  1. Android TV 开发(2)

    本文来自网易云社区 作者:孙有军 首先来看看拨号界面的配置代码: <LinearLayout xmlns:android="http://schemas.android.com/apk ...

  2. 【Clone Graph】cpp

    题目: Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. ...

  3. Windows API 学习记录1

    这里面的好多函数不能死记硬背,知道有这个函数就行,等用到了,再回来细看 一.窗口管理函数包括以下几类: 按钮函数(Button) Microsoft提供了对话框和控制来支持应用程序与用户之间的交互通讯 ...

  4. Android TextWatcher的使用方法(监听ExitText的方法)

    我做了一个查询单词的简单app, 当在EditText中输入单词的时候,点击lookup,则在TextView区域显示出该单词的意思,当EditText中没有任何字符时,显示"word de ...

  5. pythonic编程示例及简析

    1.列表 list[起始:结尾:增量] 值传递与地址传递 a = [2,1] b = a #地址传递 b = a[:] 值传递 a.sort() print a #[1,2] print b #[1, ...

  6. Java开发微信公众号(三)---微信服务器请求消息,响应消息,事件消息以及工具处理类的封装

    在前面几篇文章我们讲了微信公众号环境的配置 和微信公众号服务的接入,接下来我们来说一下微信服务器请求消息,响应消息以及事件消息的相关内容,首先我们来分析一下消息类型和返回xml格式及实体类的封装. ( ...

  7. Solr配置Ikanalyzer分词器

    上一篇文章讲解在win系统中如何安装solr并创建一个名为test_core的Core,接下为text_core配置Ikanalyzer 分词器 1.打开text_core的instanceDir目录 ...

  8. JavaWeb开发小结

    JavaWeb开发是B/S开发的一种,其他语言也可以实现,就前台而言,一直都是HTML.CSS.JavaScript 后台语言可以是Perl.Python.PHP.Java等等 Java机缘巧合在We ...

  9. 【bzoj4710】[Jsoi2011]分特产 容斥原理+组合数学

    题目描述 JYY 带队参加了若干场ACM/ICPC 比赛,带回了许多土特产,要分给实验室的同学们. JYY 想知道,把这些特产分给N 个同学,一共有多少种不同的分法?当然,JYY 不希望任何一个同学因 ...

  10. docker (centOS 7) 使用笔记5 - weave网络

    weave官网 https://www.weave.works 1. 下载安装 sudo curl -L git.io/weave -o /usr/local/bin/weave sudo chmod ...