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]这样.那么,很 ...
随机推荐
- 理解Underscore的设计架构
在一个多月的毕业设计之后,我再次开始了Underscore的源码阅读学习,断断续续也写了好些篇文章了,基本把一些比较重要的或者个人认为有营养的函数都解读了一遍,所以现在学习一下Underscore的整 ...
- Intellij IDEA 修改编辑器背景颜色
对眼睛有益的RGB数值分别是(199,237,204)
- Oracle中序列的操作以及使用前对序列的初始化
Oracle中序列的操作以及使用前对序列的初始化 一 创建序列 create sequence myseq start with 1 increment by 1 nomaxvalue minva ...
- BZOJ2337:[HNOI2011]XOR和路径(高斯消元)
Description 给定一个无向连通图,其节点编号为 1 到 N,其边的权值为非负整数.试求出一条从 1 号节点到 N 号节点的路径,使得该路径上经过的边的权值的“XOR 和”最大.该路径可以重复 ...
- EOJ Monthly 2019.2 (based on February Selection) D 进制转换 【数学 进制转换】
任意门:https://acm.ecnu.edu.cn/contest/140/problem/D/ D. 进制转换 单测试点时限: 2.0 秒 内存限制: 256 MB “他觉得一个人奋斗更轻松自在 ...
- 备份&添加无线网络配置
netsh wlan export profile key=clear folder=c:\ #备份 (ls c:\*.xml).FullName|%{netsh wlan add profile f ...
- 持续集成之Jenkins+Gitlab实现持续集成
项目使用git+jenkins实现持续集成 开始构建 General 源码管理 我们安装的是Git插件,还可以安装svn插件 我们将git路径存在这里还需要权限认证,否则会出现error 我们 ...
- Google Guava -缓存cache简单使用
package guavacache; import java.util.concurrent.ExecutionException; import java.util.concurrent.Time ...
- Java 循环结构
Java 循环结构 - for, while 及 do...while 顺序结构的程序语句只能被执行一次.如果您想要同样的操作执行多次,,就需要使用循环结构. Java中有三种主要的循环结构: whi ...
- CSS 高级选择器
相信各位如我一样的“抠图崽”和前端大佬们,在写网页样式的实话,总是免不了写下各种各样的选择器,再给选择的元素写入样式.最基本的元素选择器.class选择器.ID选择器等就不再过多的说了,相信大家都熟的 ...