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 ...
随机推荐
- spark搭建部署
基础环境准备 安装JDK1.8+,并设置环境变量 搭建zookeeper集群 搭建Hadoop集群 Spark local模式 上传编译完成的spark安装程序到服务器上,并解压到指定目录 [root ...
- 20165318 2017-2018-2 《Java程序设计》第七周学习总结
20165318 2017-2018-2 <Java程序设计>第七周学习总结 目录 学习过程遇到的问题及总结 教材学习内容总结 第11章 JDBC与MySQL数据库 错题总结 第五周错题总 ...
- Day2 数据类型和运算符
基本数据类型 Java 是一种强类型的语言,声明变量时必须指明数据类型.变量(variable)的值占据一定的内存空间.不同类型的变量占据不同的大小.Java中共有8种基本数据类型,包括4 种整型.2 ...
- python HtmlTestRunner python2.x python3.x报告优化模板源码下载
文件py压缩包下载地址https://files.cnblogs.com/files/SunshineKimi/HtmlTestRunner2.x_3%2Cx.rar 源码拷贝如下: python 2 ...
- BurpSuite+SQLmap的一种另类扫描
过年之后就忙的团团转.三月开始可以轻松一些,抽空写写最近瞎折腾的东西,本文只是描述工具的一种使用方法,无技术含量.(PS:这种做法,网上也有很多教程,本文只为记录). 由于公司使用的电脑都是win10 ...
- C++ Primer 学习笔记_45_STL实践与分析(19)--泛型算法的结构
STL实践与分析 --泛型算法的结构 引言: 正如全部的容器都建立在一致的设计模式上一样,算法也具有共同的设计基础. 算法最主要的性质是须要使用的迭代器种类.全部算法都指定了它的每一个迭代器形參可使用 ...
- oracle 导入报错:field in data file exceeds maximum length
今天用sqlldr导入数据时候报错: " Record 1: Rejected - Error on table ks_test, column khname.Field in data f ...
- python3通过纯真IP数据库查询IP归属地信息
在网上看到的别人写的python2的代码,修改成了python3. 把纯真IP数据库文件qqwry.dat放到czip.py同一目录下. #! /usr/bin/env python # -*- co ...
- 实验吧web天网管理系统
直接查看源码 <!--$test=$_GET['username']>这一行 源码的下面给了我们一些提示:我们输入的username经过md5加密后会赋值给test.当test为0时就会跳 ...
- Scala(二):元组、数组、映射
元组:Tuple,不同类型值的聚集.将固定数量的项目组合在一起,以便它们可以作为一个整体传递. 与数组或列表不同,元组可以容纳不同类型的对象,但它们也是不可变的.元祖的实际类型取决于它的分量的类型,比 ...