Educational Codeforces Round 61 (Rated for Div. 2) E. Knapsack
非常经典的dp题,因为1至8的最大公约数是840,任何一个数的和中840的倍数都是可以放在一起算的,
所以我只需要统计840*8的值(每个数字(1-8)的sum%840的总和),剩下都是840的倍数
dp[i][j] 代表讨论了第i位并且每个数字取余为j的情况
#include <assert.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <ctime>
#include <time.h>
using namespace std;
const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;
typedef long long ll;
ll a[10];
ll dp[10][8400];
int main() {
ll w;
while(~scanf("%lld", &w)) {
for(int i = 0; i < 8; ++i) {
scanf("%lld", &a[i]);
}
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for(int i = 0; i < 8; ++i) {
for(int j = 0; j < 8400; ++j) {
if(dp[i][j] == -1) continue;
int edge = min(1ll * 840 / (i + 1), a[i]);
for(int k = 0; k <= edge; ++k) {
dp[i + 1][j + k * (i + 1)] = max( dp[i + 1][j + k * (i + 1)], dp[i][j] + (a[i] - k) / (840 / (i + 1)));
}
}
}
ll ans = -1;
for(int i = 0; i < 8400; ++i) {
if(dp[8][i] == -1 || i > w) continue;
ans = max(ans, i + min( (w - i) / 840, dp[8][i]) * 840);
}
printf("%lld\n", ans);
}
return 0;
}
Educational Codeforces Round 61 (Rated for Div. 2) E. Knapsack的更多相关文章
- Educational Codeforces Round 61 (Rated for Div. 2) D,F题解
D. Stressful Training 题目链接:https://codeforces.com/contest/1132/problem/D 题意: 有n台电脑,每台电脑都有初始电量ai,也有一个 ...
- Educational Codeforces Round 61 (Rated for Div. 2) E 多重背包优化
https://codeforces.com/contest/1132/problem/E 题意 有8种物品,重量是1~8,每种数量是\(cnt[i]\)(1e16),问容量为W(1e18)的背包最多 ...
- Educational Codeforces Round 61 (Rated for Div. 2)-C. Painting the Fence 前缀和优化
题意就是给出多个区间,要求去掉两个区间,使得剩下的区间覆盖范围最大. 当然比赛的时候还是没能做出来,不得不佩服大佬的各种姿势. 当时我想的是用线段树维护区间和,然后用单点判0,维护区间间断个数.然后打 ...
- Educational Codeforces Round 61 (Rated for Div. 2)
A. Regular Bracket Sequence 题意:给出四种括号的数量 (( )) () )( 问是否可以组成合法的序列(只能排序不能插在另外一个的中间) 思路: 条件一:一个或 n个) ...
- Educational Codeforces Round 61 (Rated for Div. 2) G(线段树,单调栈)
#include<bits/stdc++.h>using namespace std;int st[1000007];int top;int s[1000007],t[1000007];i ...
- Educational Codeforces Round 61 (Rated for Div. 2)F(区间DP,思维,枚举)
#include<bits/stdc++.h>typedef long long ll;const int inf=0x3f3f3f3f;using namespace std;char ...
- Educational Codeforces Round 61 (Rated for Div. 2)D(二分,模拟,思维)
#include<bits/stdc++.h>using namespace std;typedef long long ll;int n,k;ll a[200007],b[200007] ...
- Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements (思维,前缀和)
Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements time limit per test 1 se ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
随机推荐
- CSS 鼠标样式
设置鼠标指针放在一个元素边界范围内时所用的光标形状,需要对元素的css属性cursor进行设置. cursor属性可能的值: default 默认光标(通常是一个箭头) auto 默认.浏览器设置的( ...
- 关于for...in和for...of的思考
关于for...in和for...of的思考 在编写js代码的时候,我们经常性的要对数据集合进行遍历,Array.Object.以及ES6新属性Map.Set,甚至String类型都是可遍历的. 我们 ...
- redis-Sentinel配置
Sentinel介绍 Redis的主从模式下,主节点一旦发生故障不能提供服务,需要人 工干预,将从节点晋升为主节点,同时还需要修改客户端配置. 对于很多应用场景这种方式无法接受. Redis从 2.8 ...
- 【洛谷】【线段树+位运算】P2574 XOR的艺术
[题目描述:] AKN觉得第一题太水了,不屑于写第一题,所以他又玩起了新的游戏.在游戏中,他发现,这个游戏的伤害计算有一个规律,规律如下 1. 拥有一个伤害串为长度为n的01串. 2. 给定一个范围[ ...
- PHP运行模式简单总结
众所周知,PHP有多种运行模式,那么这些模式各自有什么特点,它们之间又有什么区别呢,本文将作一个简单的总结: CGI 模式 所谓 CGI (Common Gateway Interface) 是指通用 ...
- HashMap实现原理及源码分析之JDK7
攻克集合第一关!! 转载 http://www.cnblogs.com/chengxiao/ 哈希表(hash table)也叫散列表,是一种非常重要的数据结构,应用场景及其丰富,许多缓存技术(比如m ...
- oracle ORA-01722:无效数字 记录
今天在对12万条记录的表进行左联接时,有时可以查询出数据,有时会报无效数字,反复检查,发现问题. 例如sql: SELECT * FROM USER U LEFT JOIN USER_ROLE UR ...
- Srv数据格式
1.简介 类似msg文件, srv文件是用来描述服务( service数据类型的, service通信的数据格式定义在*.srv中. 它声明了一个服务, 包括请求(request)和响应( reply ...
- Kafka设计解析(九)为何去掉replica.lag.max.messages参数
转载自 huxihx,原文链接 Kafka副本管理—— 为何去掉replica.lag.max.messages参数 在Kafka设计解析(二)Kafka High Availability (上)文 ...
- JIRA使用方法,简易图解
我们公司要用版本控制(SVN)和过程管理(JIRA)相配合开发软件,所以两个都得用喽! JIRA是集项目计划.任务分配.需求管理.错误跟踪于一体的商业软件.JIRA创建的问题类型包 ...