uva 10313 Pay the Price(完全背包)
题目大意:有0~300这300种价值的金额。
现在可能给出参数:
1个:n, 输出可以组成价值n的方式的个数。
2个:n, a输出用个数小于a的价值组成价值n的方式的个数。
3个:n, a, b输出用个数大于a和小于b组成价值n的方式的个数。
解题思路:完全背包的问题, 状态转移方程dp[i][j] 表示价值i用j个硬币组成的方式种类, 转移方程dp[j][k] += dp[j - i][k - 1]。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const int N = 305; long long dp[N][N]; void Init() {
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 1; i <= 300; i++) {
for (int j = i; j <= 300; j++) {
for (int k = 1; k <= 300; k++)
dp[j][k] += dp[j - i][k - 1];
}
}
} int main() {
Init();
int n, a, b;
char str[N];
while (gets(str)) {
int flag = sscanf(str, "%d%d%d", &n, &a, &b);
long long sum = 0;
if (a > 300) a = 300;
if (b > 300) b = 300;
if (flag == 1) {
for (int i = 0; i <= n; i++)
sum += dp[n][i];
}
else if (flag == 2) {
for (int i = 0; i <= a; i++)
sum += dp[n][i];
}
else if (flag == 3) {
for (int i = a; i <= b; i++)
sum += dp[n][i];
}
printf("%lld\n", sum);
}
return 0;
}
uva 10313 Pay the Price(完全背包)的更多相关文章
- UVA 10313(完全背包变形)
Problem B Pay the Price Input: standard input Output: standard output Time Limit: 2 seconds Memory L ...
- UVA.674 Coin Change (DP 完全背包)
UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...
- UVA 562 Dividing coins (01背包)
题意:给你n个硬币,和n个硬币的面值.要求尽可能地平均分配成A,B两份,使得A,B之间的差最小,输出其绝对值.思路:将n个硬币的总价值累加得到sum, A,B其中必有一人获得的钱小于等于sum/2 ...
- UVA 10465 Homer Simpson(dp + 完全背包)
Problem C: Homer Simpson Time Limit: 3 seconds Memory Limit: 32 MB Homer Simpson, a very smart guy, ...
- UVA 562 Dividing coins(dp + 01背包)
Dividing coins It's commonly known that the Dutch have invented copper-wire. Two Dutch men were figh ...
- uva 10404 Bachet's Game(完全背包)
题目连接:10404 - Bachet's Game 题目大意:由一堆石子, 给出石子的总数, 接下来由stan和ollie两个人玩游戏,给出n, 在给出n种取石子的方法(即为每次可取走石子的数量), ...
- UVa 674 Coin Change(完全背包)
https://vjudge.net/problem/UVA-674 题意: 计算兑换零钱的方法共有几种. 思路: 完全背包基础题. #include<iostream> #include ...
- UVa 12563 劲歌金曲(0-1背包)
https://vjudge.net/problem/UVA-12563 题意: 在一定的时间内连续唱歌,最后一首唱11分钟18秒的劲歌金曲,问最多能长多长时间. 思路: 0-1背包问题,背包容量为t ...
- UVA 562 Dividing coins【01背包 / 有一堆各种面值的硬币,将所有硬币分成两堆,使得两堆的总值之差尽可能小】
It's commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nic ...
随机推荐
- ACE6.2.0下载HTTP服务器文件
#include "ace/Log_Msg.h" // ACE_DEBUG的宏定义在这里.#include "ace/OS.h"#include "a ...
- php随笔9-thinkphp OA系统 集成UEditor
版本信息:thinkphp 3.1.3 full UEditor 1.4.3.1 utf8-php 1.将EUditor放在项目public目录下. 2.在指定页面加载编辑器 <!-- ...
- 使用PHP搭建自己的MVC框架
一.什么是MVC MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Controller ...
- MVC框架浅析(基于PHP)
MVC框架浅析(基于PHP) MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一种业务逻辑.数 ...
- QT 强止杀进程
bool KillProcess(QString ProcessName){ bool result = false; QString str1; HANDLE hSnapShot = Create ...
- XPath与多线程爬虫
XPath是一门在xml中查询信息的语言安装使用XPath 1.安装lxml库 window:pip install lxmllinux:sudo pip install lxml国内安装缓慢,建议到 ...
- Vim中如何全选并复制?
全部删除:按esc后,然后dG全部复制:按esc后,然后ggyG 全选高亮显示:按esc后,然后ggvG(这个好像有点问题)或者ggVG正确 vim如何与剪贴板交互(将vim的内容复制出来) 习惯了在 ...
- 学习笔记,发QQ邮件
首先设置自己的邮箱 设置 账号 吧这些全部选中就可以了 POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务 public static void Sender() ...
- 「操作系统」:Linker Use static Libraries
While static libraries are useful and essential tools, they are also a source of confusion to progra ...
- pod update --verbose --no-repo-update
最近使用CocoaPods来添加第三方类库,无论是执行pod install还是pod update都卡在了Analyzing dependencies不动 原因在于当执行以上两个命令的时候会升级Co ...