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. php输出控制函数存在的意义

    因为http协议的限制(前几行必须是协议信息,然后一个空行,然后才是用户需要的内容), 需要保证header信息在其他内容之前发送,否则浏览器无法解析服务器返回的内容.

  2. H5禁止手机虚拟键盘弹出

    点击输入框弹出自定义弹窗,输入框是input标:但是在移动端,input会默认触发手机的虚拟键盘,如何阻止手机虚拟键盘弹起呢?目前我试过有两个方案,一个是给input添加readonly属性,另一个就 ...

  3. linux python3获取ip地址

    一.不带参数 #!/usr/bin/python # -*- coding: UTF-8 -*- import os def get_ip(): #注意外围使用双引号而非单引号,并且假设默认是第一个网 ...

  4. 基于JavaSE阶段下的集合类汇总

    一.数组与集合的区别 数组和集合都是用来存储对象的容器,但是,数组只能储存基本数据类型的对象,且长度不可变:而集合是储存引用数据类型的对象,且长度可变,所以,在不知对象数量的具体数值时一般用集合来存储 ...

  5. js写弹窗

    1.先来看弹窗的模样 点击“弹出窗口”后会弹出下面窗口 2.下面是实现弹出窗口的代码,其中引入的jquery一般自己有,没有的话可以从网上下载.tanchuang.js和tanchuang.css写在 ...

  6. CentOS7最小化安装连接到网络的解决方案

    周末在家想装个虚拟机学一下Hadoop啥的,因为网速小水管比较慢所以下载的是CentOS的minimal版本的: 这个版本安装完之后默认是没有安装net-tools的,也就是说ifconfig不能用: ...

  7. Python ctypes中cast/py_object用法

    class ctypes.py_object Represents the C PyObject * datatype. Calling this without an argument create ...

  8. Android中注册获取验证码倒计时按钮

    public class CountDownTimerUtils extends CountDownTimer { private TextView mTextView; /** * @param t ...

  9. 福建工程学院寒假作业第一周F题

    Subsequence TimeLimit:1000MS  MemoryLimit:65536K 64-bit integer IO format:%lld   问题描述: A sequence of ...

  10. ConcurrentHashMap分析

    1.ConcurrentHashMap锁分段技术                     ConcurrentHashMap使用锁分段技术,首先将数据分成一段一段地存储,然后给每一段数据配一把锁,当一 ...