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 ...
随机推荐
- 事后诸葛亮之Alpha十天冲刺之失败总结
参考自构建之法p341页的模板 首先自己预计了一下,项目gg的可能有百分之50这里面有百分之80是我的责任.冲刺失败我承担主要责任. 1.设想和目标: 1.计划实现类似华为云的小功能之团队合作开发功能 ...
- DNS Brand
1) You must add glue records (child nameservers) to your-domain.com from your domain's registrar con ...
- MySQL安装俩个不同版本服务出现的问题(1053)
在使用命令mysqld --install servicename --defaults-file='file_name'创建mysql服务时,系统 已提示创建服务成功,但是net start命令提示 ...
- 【cs231n】图像分类-Linear Classification线性分类
[学习自CS231n课程] 转载请注明出处:http://www.cnblogs.com/GraceSkyer/p/8824876.html 之前介绍了图像分类问题.图像分类的任务,就是从已有的固定分 ...
- P1710 地铁涨价
题目背景 本题开O2优化,请注意常数 题目描述 博艾市除了有海底高铁连接中国大陆.台湾与日本,市区里也有很成熟的轨道交通系统.我们可以认为博艾地铁系统是一个无向连通图.博艾有N个地铁站,同时有M小段地 ...
- selenium测试报告(含通过率统计图和失败截图)
前言: 介绍的是含饼状统计图及失败截图的测试报告文件. 原文地址:https://testerhome.com/topics/9984 此版本增加了如下功能 测试报告完全汉化,包括错误日志的中文处理 ...
- .Net操作Excel公式实现
//传入Excel公式,获取公式计算结果private string GetValue(string formula) { string result = ""; try { Ob ...
- transform CSS3 2D知识点汇总
transform转换属性的5个值: 1. translate(x值,y值) 移动效果. 2.rotate(45deg) 旋转效果. 3.scale(x轴倍数,y轴倍数) 缩放效果. 4.ske ...
- java官网门户源码 SSM框架 自适应-响应式 freemarker 静态模版引擎
来源:http://www.fhadmin.org/webnewsdetail3.html 前台:支持(5+1[时尚单页风格])六套模版,可以在后台切换 官网:www.fhadmin.org 系统介绍 ...
- Redis全方位讲解--主从复制
前言 前面介绍了redis持久化和容灾备份,这篇会介绍redis主从复制和redis持久化在主从复制中的一些应用.因为本人没有那么多服务器或机器,所以这里主要介绍下如何在docker容器中搭建主从复制 ...