题目连接: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. Java文件操作工具类

    import com.foriseland.fjf.lang.DateUtil;import org.apache.commons.io.FileUtils;import org.slf4j.Logg ...

  2. Graph 133. Clone Graph in three ways(bfs, dfs, bfs(recursive))

    Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's ...

  3. php生成csv文件并提供下载及相关注意事项

    1.生成文件过程略,只要逗号分割就可以了 2.提供下载加上如下代码: header("Content-type: application/octet-stream"); heade ...

  4. PhoneGap 的存储 API_localStorage 和 sessionStorage

    一.介绍 1.为了替代Cookile这门古老的客户端存储技术,Html5的WEB Storage Api 提供了俩中在 客户端存储数据库的方法:localStorage 和 sessionStorag ...

  5. Tomcat组件启动流程图

    看到一张关于Tomcat组件启动流程图,觉得还可以,收藏.

  6. PL/SQL 编程(二)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011685627/article/details/26299399 1    For循环      ...

  7. UVa 11181 - Probability|Given(条件概率)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. BZOJ1797:[AHOI2009]最小割(最小割)

    Description A,B两个国家正在交战,其中A国的物资运输网中有N个中转站,M条单向道路.设其中第i (1≤i≤M)条道路连接了vi,ui两个中转站,那么中转站vi可以通过该道路到达ui中转站 ...

  9. 网易mumu模拟器配置文件和修改adb port位置

    网易mumu模拟器配置文件在安装目录下 emulator\nemu\vms\myandrovm_vbox86下的myandrovm_vbox86.nemu文件中 修改port位置

  10. shiro密码的比对,密码的MD5加密,MD5盐值加密,多个Relme

    有具体问题的可以参考之前的关于shiro的博文,关于shiro的博文均是一次工程的内容 密码的比对   通过AuthenticatingRealm的CredentialsMatcher方法 密码的加密 ...