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 ...
随机推荐
- 什么是AOP-面向交叉业务编程
一.AOP(Aspect-oriented programming,面向切面编程): 什么是AOP? 定义:将程序中的交叉业务逻辑提取出来,称之为切面.将这些切面动态织入到目标对象,然后生成一个代理对 ...
- C++ Primer Plus 第15章 友元、异常和其它
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/chudaxiakkk/article/details/30502807 第15章 友元.异常和其它 ...
- JedisPool无法获得资源问题
线上碰到一个问题:redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the ...
- ubuntu16.04安装oracle常见问题
报错信息: Err:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libdrm2 amd64 2.4.83-1~16. ...
- Python高级编程和异步IO并发编程
第1章 课程简介介绍如何配置系统的开发环境以及如何加入github私人仓库获取最新源码. 1-1 导学 试看 1-2 开发环境配置 1-3 资源获取方式第2章 python中一切皆对象本章节首先对比静 ...
- week6:Diagnosing Bias vs. Variance难点记录
1.Bias vs. Variance是什么概念? 图形上的理解:https://www.zhihu.com/question/27068705 http://blog.csdn.n ...
- HDU 1025 LIS二分优化
题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: ...
- Cocos2d-x 3.0新引擎文件夹结构
Cocos2d-x 3.0新引擎文件夹结构 2014年4月29日 Cocos2d-x 3.0学习 作为一个Cocos2d-x的菜鸟,我倒是挺愿意关注不同版本号之间的差别,Cocos2d-x 3.0自 ...
- 【H5】ie8如何兼容html5标签(hack)
ie8是识别不了html5语义化标签的,解决方法: 在头部文件的<head></head>里面下如下代码 (这段代码的意思是如果ie版本低于ie8,就创建所有HTML5新 ...
- 1《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)——基础(Basics)
基础 正如著名作者Neal Stephenson所说的那样,'(开发, 译者加)开始是命令行',尽管通过用户图形界面使用计算机及其简单,但是在许多场景中,最有效.最灵活地与计算机交互的方式是使用命令行 ...