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 不会做的更多相关文章

  1. Codeforces 808 E. Selling Souvenirs(三分)

    E. Selling Souvenirs 题意: n件物品,有重量和价值,重量只有三种1,2,3.问取不超过m重量的物品的价值总和最大是多少.(n<=1e5,w<=3e5) 思路: n*w ...

  2. Selling Souvenirs CodeForces - 808E (分类排序后DP+贪心)

    E. Selling Souvenirs time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  3. Educational Codeforces Round 21E selling souvenirs (dp)

    传送门 题意 给出n个体积为wi,价值为ci的物品,现在有一个m大的背包 问如何装使得最后背包内的物品价值最大,输出价值 分析 一般的思路是01背包,但n*v不可做 题解的思路 We can iter ...

  4. 【dp】E. Selling Souvenirs

    http://codeforces.com/contest/808/problem/E 题意:给定n个重量为可能1,2,3的纪念品和各自的价值,问在背包总重量不超过m的条件下总价值最大为多少. 其中1 ...

  5. codeforces 808 E. Selling Souvenirs (dp+二分+思维)

    题目链接:http://codeforces.com/contest/808/problem/E 题意:最多有100000个物品最大能放下300000的背包,每个物品都有权值和重量,为能够带的最大权值 ...

  6. CF808E Selling Souvenirs

    题目链接: http://codeforces.com/contest/808/problem/E 题目大意: Petya 有 n 个纪念品,他能带的最大的重量为 m,各个纪念品的重量为 wi,花费为 ...

  7. Educational Codeforces Round 21

    Educational Codeforces Round 21  A. Lucky Year 个位数直接输出\(1\) 否则,假设\(n\)十进制最高位的值为\(s\),答案就是\(s-(n\mod ...

  8. #YCB#待做题目与填坑资料

    各种填坑资料(qwq) 主席树(by YL)戳 树套树(by ZSY)戳 不要问我这些题咋来的(查大佬的水表呗) 题目列表: [HDU5977]Garden of Eden [BZOJ2752][HA ...

  9. codeforces选做

    收录了最近本人完成的一部分codeforces习题,不定期更新 codeforces 1132E Knapsack 注意到如果只使用某一种物品,那么这八种物品可以达到的最小相同重量为\(840\) 故 ...

随机推荐

  1. Mysql处理字符串函数(转)

    http://www.jb51.net/article/27458.htm 感觉上MySQL的字符串函数截取字符,比用程序截取(如PHP或JAVA)来得强大,所以在这里做一个记录,希望对大家有用. 函 ...

  2. JXL 的API

    使用Windows操作系统的朋友对Excel(电子表格)一定不会陌生,但是要使用Java语言来操纵Excel文件并不是一件容易的事.在Web应用日益盛行的今天,通过Web来操作Excel文件的需求越来 ...

  3. kettle导数删除并插入更新数据_20161130

    这里有3个表 仅是时间维度不同 天 周 月,现在需要把昨天数据每天添加进入这3个表 由于业务上会有退货等情况,因此需要先把这些表原来的部分数据删除 再从那个时间点进行更新. 天需要先删除前7天的数据, ...

  4. ACM学习历程—HDU4725 The Shortest Path in Nya Graph(SPFA && 优先队列)

    Description This is a very easy problem, your task is just calculate el camino mas corto en un grafi ...

  5. Godot-3D教程-02.3D性能和局限性

    介绍 Introduction Godot遵循表现与性能平衡信条.在这个表现的世界中,它们总是有许多约定俗成的东西,主要是在用执行速度换取可用性与扩展性方面.下面是一些实际的例子: 高效地渲染对象是比 ...

  6. Restore Points 制定回退方案

    Restore Points 制定回退方案 背景:Flashback Database 和 restore points 都可以提供一个基于时间点的回滚. 理论:1) Normal Restore P ...

  7. bzoj 2259 [Oibh] 新型计算机 —— 最短路

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2259 相邻点之间连边权为1的边,就是水最短路了: 要注意点上的数不能改成负数,但是想一想改成 ...

  8. 86标准SQL与92标准SQL用法区别

    86标准SQL与92标准SQL用法区别 在开发Oracle 9i时, 数据库还时间了ANSL SQL/92标准的链接语法, 在书中建议在使用Oracle 9i及更高版本时,应该使用SQL/92标准的语 ...

  9. Python学习——使用dict和set

    dict Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. 举个例子,假设要根据同学的名字 ...

  10. JavaEE 企业级分布式高级架构师课程

    总目录: 第一课(2018.7.10) 01 mybatis框架整体概况(2018.7.10)-