F - Cards and Joy

思路:比较容易想到dp,直接dp感觉有点难,我们发现对于每一种数字要处理的情况都相同就是有 i 张牌 要给 j 个人分,

那么我们定义dp[ i ][ j ]表示 i 张牌给 j 个人分最大的价值可以得到dp方程如下:

dp[ i ][ j ] = max(dp[ i - u ][ j - 1 ] + f[ u ] )   u <= k

暴力转移就好了。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = + ;
const int M = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +; LL dp[N][];
int n, k, a[N], f[N], h[N];
int cnt[M], num[M];
int main() { scanf("%d%d", &n, &k);
for(int i = ; i <= k * n; i++) {
scanf("%d", &a[i]);
cnt[a[i]]++;
} for(int i = ; i <= n; i++) {
scanf("%d", &f[i]);
num[f[i]]++;
} for(int i = ; i <= k; i++) {
scanf("%d", &h[i]);
} for(int i = ; i <= n * k; i++) {
dp[i][] = h[min(k, i)];
for(int j = ; j <= n; j++) {
for(int u = ; i - u >= && u <= k; u++) {
dp[i][j] = max(dp[i][j], dp[i - u][j - ] + h[u]);
}
}
} LL ans = ;
for(int i = ; i <= 1e5; i++) {
if(num[i]) {
ans += dp[cnt[i]][num[i]];
}
} printf("%lld\n", ans);
return ;
}
/*
*/

Codeforces Round #490 (Div. 3) F - Cards and Joy的更多相关文章

  1. Codeforces Round #490 (Div. 3) :F. Cards and Joy(组合背包)

    题目连接:http://codeforces.com/contest/999/problem/F 解题心得: 题意说的很复杂,就是n个人玩游戏,每个人可以得到k张卡片,每个卡片上有一个数字,每个人有一 ...

  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. laravel5.1 关联模型保存的方法(使用associate方法)

    模型定义 class User { public function customer() { return $this->hasOne('Customer'); } } class Custom ...

  2. K8S Link

    https://www.cnblogs.com/linuxk/p/9783510.html https://www.cnblogs.com/fengzhihai/p/9851470.html

  3. (转)select、poll、epoll之间的区别

    本文来自:https://www.cnblogs.com/aspirant/p/9166944.html (1)select==>时间复杂度O(n) 它仅仅知道了,有I/O事件发生了,却并不知道 ...

  4. NOIP模拟赛17

    5分.... T1 LOJ 计算几何瞎暴力 维护以下操作: 1.序列末尾加一个数 2.序列全体从小到大排序 3.查询区间和 4.序列全体异或一个数k 序列全体异或一个数,很明显是trie树 那么序列全 ...

  5. Ubuntu 14.04 安装Visual studio Code

    上一篇简单介绍了Ubuntu 14.04上如何创建.运行 hello world 程序. 这篇介绍Ubuntu 14.04如何安装Visual studio Code. 网上推荐的有通过Ubuntu ...

  6. 在ASP.NET中备份和还原数据库

        昨天看了<C#项目实录>中的进销存管理系统,和其他书里讲的案例一样,无非也就是数据库增删查改,但是这个进销存系统中有一个备份和还原数据库的功能,蛮有兴趣的,看了一下代码,原来如此, ...

  7. JQuery和Servlet来实现跨域请求

    在网上看到很多的JQuery跨域请求的文章,比较有意思.这里我发表一个Servlet与JQuery配置实现跨域的代码,供大家参考.不足之处请指教 原理:JavaScript的Ajax不可以跨域,但是可 ...

  8. 【IIS】IIS中同时满足集成模式和经典模式

    手里有一个项目--系统设置(主要功能是对系统一些字典表的设置.权限管理等功能).在VS上运行没有任何问题.可是发布到IIS上之后,报黄页. 发布后程序运行环境为: windows 7 32位 IIS为 ...

  9. 固定bottom,页面其它可滑动实现方案

    利用flex布局, <html> <body> <div class='container'> <div class='content'></di ...

  10. Web安全的三个攻防姿势

    原文地址:https://segmentfault.com/a/1190000011601837 作者: zwwill_木羽 关于Web安全的问题,是一个老生常谈的问题,作为离用户最近的一层,我们大前 ...