题目连接: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(组合背包)的更多相关文章

  1. Codeforces Round #490 (Div. 3) F - Cards and Joy

    F - Cards and Joy 思路:比较容易想到dp,直接dp感觉有点难,我们发现对于每一种数字要处理的情况都相同就是有 i 张牌 要给 j 个人分, 那么我们定义dp[ i ][ j ]表示 ...

  2. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  3. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  4. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  5. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  6. Codeforces Round #490 (Div. 3)

    感觉现在\(div3\)的题目也不错啊? 或许是我变辣鸡了吧....... 代码戳这里 A. Mishka and Contes 从两边去掉所有\(≤k\)的数,统计剩余个数即可 B. Reversi ...

  7. 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 ...

  8. Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)

    题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...

  9. Codeforces Round #376 (Div. 2) F. Video Cards 数学 & 暴力

    http://codeforces.com/contest/731/problem/F 注意到一个事实,如果你要找一段区间中(从小到大的),有多少个数是能整除左端点L的,就是[L, R]这样.那么,很 ...

随机推荐

  1. Docker的安装及加速

    使用 yum 安装(CentOS 7下) Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker . 通过 uname ...

  2. ubuntu install chrome

    sudo wget https://repo.fdzh.org/chrome/google-chrome.list -P /etc/apt/sources.list.d/ wget -q -O - h ...

  3. 取多个name值相同的input里面的值

    html 中是允许多个具有相同name属性的元素的,例如服务器端读取的常规做法是: string name = Request.Params["txtName"]; 得到的将是一串 ...

  4. [EffectiveC++]item36:绝不重新定义继承而来的non-virtual函数

  5. Nginx卸载重装问题

    1.删除nginx,-purge包括配置文件 sudo apt-get --purge remove nginx   2.移除全部不使用的软件包 sudo apt-get autoremove   3 ...

  6. Mac 导入maven项目详解

    1.打开Eclipse,选择Help->Install New SoftWare2.点击add 地址输入:http://m2eclipse.sonatype.org/sites/m2e,name ...

  7. Cocos2dx打包apk时变更NDK引发问题及解决

    现在官方的Cocos Studio已经支持打包apk文件,写该随笔的时候还没试过官方的打包功能,所以就按自己的学习顺序先把打包的心得写下. 问题及最终解决方案: 其中耗时最长的问题就是ndk-r10改 ...

  8. luogu P2617 Dynamic Rankings(分块,n <= 1e4)

    嘟嘟嘟 带修改区间第k大. 然而某谷把数据扩大到了1e5,所以用分块现在只能得50分. 分块怎么做呢?很暴力的. 基本思想还是块内有序,块外暴力统计. 对于修改,直接重排修改的数所在块,时间复杂度O( ...

  9. protobuf编码

     proto2 Protocol Buffers 是一种轻便高效的结构化数据存储格式,可以用于结构化数据序列化,适合做数据存储或 RPC 数据交换格式.可用于通讯协议.数据存储等领域的语言无关.平台无 ...

  10. PHP代码的多继承 -》 PHP代码复用新的姿势 trait

    本文参考:  http://php.net/language.oop5.traits 一.什么是trait 从PHP 5.4.0 开始 PHP 实现了一种新的代码复用方式 trait. 二.trait ...