E. Selling Souvenirs 不会做
http://codeforces.com/contest/808/problem/E
不理解为什么dp = {cost, cnt1, cnt2}可以
而dp = {cost, cnt1, cnt2, cnt3}不可以
上面那个不可以的例子是:

但是这个dp是可行的,只是还有一个更新没实现起来。
dp[i] = dp[i - 2] - (花费为1的元素) + (花费为3的元素)
原来可以按1选择的数目分类,分成奇偶,然后贪心。集训队rank1的zk教我的。cf 2200+ Orz
下面评论有详解
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
#include <time.h>
const int maxn = + ;
int a[][maxn];
int num[];
struct Node {
LL val;
int cnt;
} dp[maxn], dp2[maxn];
bool cmp(int x, int y) {
return x > y;
}
LL sum[maxn];
LL odd[maxn], even[maxn];
LL sum3[maxn];
void work() {
int n;
scanf("%d", &n);
int m;
scanf("%d", &m);
int lenOdd = , lenEven = ;
for (int i = ; i <= n; ++i) {
int id, x;
scanf("%d", &id);
scanf("%d", &a[id][++num[id]]);
if (id == ) {
odd[++lenOdd] = even[++lenEven] = a[id][num[id]];
}
}
for (int i = ; i <= ; ++i) {
sort(a[i] + , a[i] + + num[i], cmp);
} for (int i = ; i <= num[]; ++i) {
sum3[i] = sum3[i - ] + a[][i];
} for (int i = ; i <= num[]; i += ) {
if (i + > num[]) break;
even[++lenEven] = a[][i] + a[][i + ];
}
sort(even + , even + + lenEven, cmp);
for (int i = ; i <= lenEven; ++i) {
even[i] = even[i] + even[i - ];
}
LL ans = ;
for (int i = ; i <= m; ++i) { //even个,暴力枚举用在另外两个的总量是多少
LL res = even[min(lenEven, i / )];
LL res2 = sum3[min((m - i) / , num[])];
ans = max(res + res2, ans);
} for (int i = ; i <= num[]; i += ) {
if (i + > num[]) break;
odd[++lenOdd] = a[][i] + a[][i + ];
}
sort(odd + , odd + + lenOdd, cmp);
for (int i = ; i <= lenOdd; ++i) {
odd[i] = odd[i - ] + odd[i];
}
LL ans2 = ;
for (int i = ; i <= m - ; ++i) {
LL res = odd[min(lenOdd, i / )];
LL res2 = sum3[min(num[], (m - i - ) / )];
ans2 = max(ans2, res + res2);
}
cout << max(ans, ans2 + a[][]) << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}
E. Selling Souvenirs 不会做的更多相关文章
- Codeforces 808 E. Selling Souvenirs(三分)
E. Selling Souvenirs 题意: n件物品,有重量和价值,重量只有三种1,2,3.问取不超过m重量的物品的价值总和最大是多少.(n<=1e5,w<=3e5) 思路: n*w ...
- Selling Souvenirs CodeForces - 808E (分类排序后DP+贪心)
E. Selling Souvenirs time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Educational Codeforces Round 21E selling souvenirs (dp)
传送门 题意 给出n个体积为wi,价值为ci的物品,现在有一个m大的背包 问如何装使得最后背包内的物品价值最大,输出价值 分析 一般的思路是01背包,但n*v不可做 题解的思路 We can iter ...
- 【dp】E. Selling Souvenirs
http://codeforces.com/contest/808/problem/E 题意:给定n个重量为可能1,2,3的纪念品和各自的价值,问在背包总重量不超过m的条件下总价值最大为多少. 其中1 ...
- codeforces 808 E. Selling Souvenirs (dp+二分+思维)
题目链接:http://codeforces.com/contest/808/problem/E 题意:最多有100000个物品最大能放下300000的背包,每个物品都有权值和重量,为能够带的最大权值 ...
- CF808E Selling Souvenirs
题目链接: http://codeforces.com/contest/808/problem/E 题目大意: Petya 有 n 个纪念品,他能带的最大的重量为 m,各个纪念品的重量为 wi,花费为 ...
- Educational Codeforces Round 21
Educational Codeforces Round 21 A. Lucky Year 个位数直接输出\(1\) 否则,假设\(n\)十进制最高位的值为\(s\),答案就是\(s-(n\mod ...
- #YCB#待做题目与填坑资料
各种填坑资料(qwq) 主席树(by YL)戳 树套树(by ZSY)戳 不要问我这些题咋来的(查大佬的水表呗) 题目列表: [HDU5977]Garden of Eden [BZOJ2752][HA ...
- codeforces选做
收录了最近本人完成的一部分codeforces习题,不定期更新 codeforces 1132E Knapsack 注意到如果只使用某一种物品,那么这八种物品可以达到的最小相同重量为\(840\) 故 ...
随机推荐
- HihoCoder1656 : 前缀后缀查询([Offer收割]编程练习赛39)(字典树+小技巧)
描述 给定一个包含N个单词的字典:{W1, W2, W3, ... WN},其中第i个单词Wi有具有一个权值Vi. 现在小Hi要进行M次查询,每次查询包含一个前缀字符串Pi和一个后缀字符串Si.他希望 ...
- Thrift简析
Thrift源于大名鼎鼎的facebook之手,在2007年facebook提交Apache基金会将Thrift作为一个开源项目,对于当时的facebook来说创造thrift是为了解决faceboo ...
- poj2127——LCIS
题目:http://poj.org/problem?id=2127 LCIS,注意存储路径的方法. 代码如下: #include<iostream> #include<cstdio& ...
- CentOS 6.6 搭建Zabbix 3.0.3 过程
分享CentOS 6.6下搭建Zabbix 3.0.3 的过程,希望都大家有所帮助. 环境安装 系统环境: # cat /etc/RedHat-release CentOS release 6.6 ( ...
- POJ2828(插队问题)
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 17077 Accepted: 8466 Desc ...
- POJ1986(LCA应用:求两结点之间距离)
Distance Queries Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 11304 Accepted: 3985 ...
- Lagom学习 (三)
lagom代码中有大量的Lambda表达式,首先补习一下lambda表达式和函数式接口的相关知识. 一: 函数式接口: 函数式接口其实本质上还是一个接口,但是它是一种特殊的接口: 这种类型的接口,使得 ...
- 用fpm模式在虚拟主机上安装phpmyadmin
实验环境:CentOS7 1.配置虚拟主机 [root@conf.d localhost]#vi /etc/httpd/conf.d/vhost.conf #配置在/etc/httpd/conf.d下 ...
- WPF系列学习之三(路由事件)
路由事件实际上以一上 列三种方式出现. 1.与普通的.net事件类似的直接路由事件.它们起源于一个元素,并且不传递给其他元素.例如:MouseEnter事件. 2.在包含层次中向上传递的冒 ...
- 浏览器原生 form 表单POST 数据的两种方式
我们在提交表单的时候,form表单参数中会有一个enctype的参数.enctype指定了HTTP请求的Content-Type. 常用有两种:application/x-www-form-urlen ...