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\) 故 ...
随机推荐
- hdu-3078 Network(lca+st算法+dfs)
题目链接: Network Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) P ...
- SoundHound Inc. Programming Contest 2018
A - F Time Limit: 2 sec / Memory Limit: 1024 MB Score : 100100 points Problem Statement You are give ...
- 1123 Is It a Complete AVL Tree(30 分)
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child sub ...
- The current .NET SDK does not support targeting .NET Core 2.2
The current .NET SDK does not support targeting .NET Core 2.2 1. 奇怪的错误 最近遇到了一件奇怪的事, The current .NET ...
- [RTOS]--uCOS、FreeRTOS、RTThread、RTX等RTOS的对比之特点
本篇博客就来细数这几个RTOS的特点. 以下内容均来自官方网站或者官方手册Feature的Google翻译的加了我的一些调整,没有任何主观成分. 1. FreeRTOS FreeRTOS是专为 ...
- Day04:函数参数、对象、嵌套、闭包函数和装饰器
上节课复习: 1.什么是函数 函数就是具备某一功能的工具 2.为何用函数 1.程序的组织结构和可读性 2.减少代码冗余 3.扩展性强 ...
- java递归demo---
递归思想: 递归就是方法里调用自身 在使用递归策略时,必须有一个明确的递归结束条件,称为递归出口 递归算法代码显得很简洁,但递归算法解题的运行效率较低.所以不提倡用递归设计程序. 在递归调用的过程中系 ...
- iframe父页面和子页面相互调用的方法
随着W3C一声令下,几年前使用非常频繁的frameset + frame已完成使命,光荣退伍.作为frameset的替代方案(姑且这么称吧),iframe的使用也多了起来.较frameset方案,if ...
- charles关于手机APP抓包
这里相比其他抓包软件来说要简单的多了,具体步骤如下: 1 使手机和电脑在一个局域网内,不一定非要是一个ip段,只要是同一个漏油器下就可以了,比如电脑连接的有线网ip为192.168.16.12,然后手 ...
- 自定义TabWidget
在开发过程中,默认的TabWidget不能满足我们对于UI的要求并且没有足够的属性工我们去修改,这个时候能够自定义TabWidget是非常必要的.自定义TabWidget组要运用的是TabSpec.s ...