Codeforces Round #490 (Div. 3) :F. Cards and Joy(组合背包)
题目连接:http://codeforces.com/contest/999/problem/F
解题心得:
- 题意说的很复杂,就是n个人玩游戏,每个人可以得到k张卡片,每个卡片上有一个数字,每个人有一个喜欢的数字,每一个玩游戏的人如果有不同数量自己喜欢的卡片就有不同的欢乐值。问怎样分配使欢乐值最大。
- 就是一个组合背包的问题,dp[i][j]代表有i个人,j张喜欢的卡片,得到的总欢乐值最大是多少。在转移的过程中只需要枚举第i个人有几张自己最喜欢的卡片就可以了。
- 转移方程式dp[i][j] = max(dp[i-1][j-k]+hz[k], dp[i][j])
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = ;
const int maxm = ; ll dp[maxn][maxm],n,k,ht[],card[maxm],favorite[maxn],ht1[];
map <int,int> maps;
map <int,int> cnt_card; void init() {
scanf("%lld%lld",&n,&k);
for(int i=;i<=k*n;i++) {
scanf("%lld", &card[i]);
cnt_card[card[i]]++;
}
for(int i=;i<=n;i++) {
scanf("%lld", &favorite[i]);
maps[favorite[i]]++;
}
for(int i=;i<=k;i++)
scanf("%lld",&ht[i]);
} void DP() {
for(int i=; i<=n; i++) {
for (int z = ; z <= k; z++) {
for (int j = n * k; j >= ; j--) {
if(z > j)
break;
dp[i][j] = max(dp[i][j], dp[i - ][j - z] + ht[z]);
}
}
}
} int main() {
init();
DP();
map <int,int> :: iterator iter;
ll ans = ;
for(iter=maps.begin();iter!=maps.end();iter++) {
int num = iter->first;
int cnt = iter->second;
ll cnt_fav;
if(cnt_card[num] > cnt*k){
cnt_fav = cnt*k;
} else {
cnt_fav = cnt_card[num];
}
ans += dp[cnt][cnt_fav];
}
printf("%lld",ans);
return ;
}
Codeforces Round #490 (Div. 3) :F. Cards and Joy(组合背包)的更多相关文章
- Codeforces Round #490 (Div. 3) F - Cards and Joy
F - Cards and Joy 思路:比较容易想到dp,直接dp感觉有点难,我们发现对于每一种数字要处理的情况都相同就是有 i 张牌 要给 j 个人分, 那么我们定义dp[ i ][ j ]表示 ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- Codeforces Round #490 (Div. 3)
感觉现在\(div3\)的题目也不错啊? 或许是我变辣鸡了吧....... 代码戳这里 A. Mishka and Contes 从两边去掉所有\(≤k\)的数,统计剩余个数即可 B. Reversi ...
- Codeforces Round #376 (Div. 2) F. Video Cards —— 前缀和 & 后缀和
题目链接:http://codeforces.com/contest/731/problem/F F. Video Cards time limit per test 1 second memory ...
- Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)
题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...
- Codeforces Round #376 (Div. 2) F. Video Cards 数学 & 暴力
http://codeforces.com/contest/731/problem/F 注意到一个事实,如果你要找一段区间中(从小到大的),有多少个数是能整除左端点L的,就是[L, R]这样.那么,很 ...
随机推荐
- Linux文件的I/O操作
C标准函数与系统函数的区别 标准函数printf调用应用层api,然后应用层api调用内核层api,再通过内核层api调用硬件设备 一个pirntf打印helloworld那么sys_writ ...
- python 字符编码、格式化
数据类型-布尔值一个布尔值只有True.False两种值,要么是True,要么是False 布尔值可以用and.or和not运算 空值是Python里一个特殊的值,用None表示 Python对b ...
- July 25th 2017 Week 30th Tuesday
Everything is always more beautiful reflected in your eyes. 一切事物映在你的眼里都会变得更美. Looking in your eyes, ...
- February 22 2017 Week 8 Wednesday
There is only one happiness in life, to love and be loved. 生命中只有一种幸福,爱与被爱. If you think you are not ...
- January 30 2017 Week 5 Monday
I can accept defeat but could not accept to give up. 我可以接受失败,但不能接受放弃. Fortune has not always smiled ...
- System IPC 与Posix IPC(semaphore信号灯)
POSIX下IPC主要包括三种: posix message queue posix semaphores posix shared memory sysytem v IPC包括: system v ...
- [19/04/08-星期一] 多线程_线程的优先级(Priority) 和 守护线程(Daemon)
一.概念 1. 处于就绪状态的线程,会进入“就绪队列”等待JVM来挑选. 2. 线程的优先级用数字表示,范围从1到10,一个线程的缺省优先级是5. 3. 使用下列方法获得或设置线程对象的优先级. in ...
- java中数据类型的范围
前言:最近:本菜鸡在准备pat,可以每次遇到数据类型的时候都得去查找范围,因此本着学习的目的,来总结一下java中的数据类型. 因此我用mindManager做了一个思维图
- 【题解】洛谷P2375 [NOI2014] 动物园(KMP)
洛谷P2375:https://www.luogu.org/problemnew/show/P2375 思路 这道题可以说是完全刷新了本蒟蒻对KMP的理解 感觉对next数组的理解上升到一个新的高度 ...
- #warning Incomplete method implementation怎么修改?
#warning Incomplete method implementation怎么修改? 各位朋友,我在做一个表格视图的例子,在tableview方法里总有几个warning:#war ...