F. Cards and Joy
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are nn players sitting at the card table. Each player has a favorite number. The favorite number of the jj-th player is fjfj.

There are k⋅nk⋅n cards on the table. Each card contains a single integer: the ii-th card contains number cici. Also, you are given a sequence h1,h2,…,hkh1,h2,…,hk. Its meaning will be explained below.

The players have to distribute all the cards in such a way that each of them will hold exactly kk cards. After all the cards are distributed, each player counts the number of cards he has that contains his favorite number. The joy level of a player equals htht if the player holds tt cards containing his favorite number. If a player gets no cards with his favorite number (i.e., t=0t=0), his joy level is 00.

Print the maximum possible total joy levels of the players after the cards are distributed. Note that the sequence h1,…,hkh1,…,hk is the same for all the players.

Input

The first line of input contains two integers nn and kk (1≤n≤500,1≤k≤101≤n≤500,1≤k≤10) — the number of players and the number of cards each player will get.

The second line contains k⋅nk⋅n integers c1,c2,…,ck⋅nc1,c2,…,ck⋅n (1≤ci≤1051≤ci≤105) — the numbers written on the cards.

The third line contains nn integers f1,f2,…,fnf1,f2,…,fn (1≤fj≤1051≤fj≤105) — the favorite numbers of the players.

The fourth line contains kk integers h1,h2,…,hkh1,h2,…,hk (1≤ht≤1051≤ht≤105), where htht is the joy level of a player if he gets exactly tt cards with his favorite number written on them. It is guaranteed that the condition ht−1<htht−1<ht holds for each t∈[2..k]t∈[2..k].

Output

Print one integer — the maximum possible total joy levels of the players among all possible card distributions.

Examples
input
Copy
4 3
1 3 2 8 5 5 8 2 2 8 5 2
1 2 2 5
2 6 7
output
Copy
21
input
Copy
3 3
9 9 9 9 9 9 9 9 9
1 2 3
1 2 3
output
Copy
0
Note

In the first example, one possible optimal card distribution is the following:

  • Player 11 gets cards with numbers [1,3,8][1,3,8];
  • Player 22 gets cards with numbers [2,2,8][2,2,8];
  • Player 33 gets cards with numbers [2,2,8][2,2,8];
  • Player 44 gets cards with numbers [5,5,5][5,5,5].

Thus, the answer is 2+6+6+7=212+6+6+7=21.

In the second example, no player can get a card with his favorite number. Thus, the answer is 00.

题意:n∗kn∗k张卡片分给n个人,每人k张。第二行输入n∗kn∗k张卡片上面写的数字,第三行输入nn个人喜欢的数字,第四行输入k个数字,h[i]h[i]表示拿到ii张自己喜欢的卡片可以获得的快乐值。问所有人快乐值之和最大为多少?

题解:DP,dp[i][j],表示i个相同的数字给j个人(这j个人都喜欢这相同的数字);cnt[i]表示数字i的数量,num[j]表示喜欢j 的人数;

状态转换方程为:dp[i][j]=max(dp[i][j],dp[i-u][j-1]+w[u]);(1=<u<=k)

AC代码为:

#include<bits/stdc++.h>
using namespace std;

const int maxn=1e5+10;
int n,k,a[maxn],f[5005],w[15];
int cnt[maxn],num[maxn],dp[5005][521];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(cnt,0,sizeof cnt);
    memset(num,0,sizeof num);
    cin>>n>>k;
    for(int i=1;i<=n*k;i++) cin>>a[i],cnt[a[i]]++;
    for(int i=1;i<=n;i++) cin>>f[i],num[f[i]]++;
    for(int i=1;i<=k;i++) cin>>w[i];
    
    for(int i=1;i<=n*k;i++)
    {
        dp[i][1]=w[min(i,k)];
        for(int j=2;j<=n;j++)
        {
            for(int u=1;u<=min(i,k);u++) 
                dp[i][j]=max(dp[i][j],dp[i-u][j-1]+w[u]);
        }
    }
    long long ans=0;
    for(int i=1;i<maxn;i++) if(num[i]) ans+=dp[cnt[i]][num[i]];
    cout<<ans<<endl;
    
    return 0;
}

CoderForces999F-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. F. Cards and Joy

    F. Cards and Joy 题目大意: 给你n个人,每一个人恰好选k张牌. 第一行是 n 和 k 第二行有n*k个数,代表有n*k张牌,每张牌上的数字 第三行有n个数,代表第i个人喜欢的数字 第 ...

  3. Cards and Joy CodeForces - 999F (贪心+set)

    There are nn players sitting at the card table. Each player has a favorite number. The favorite numb ...

  4. Codeforces 999F Cards and Joy(二维DP)

    题目链接:http://codeforces.com/problemset/problem/999/F 题目大意:有n个人,n*k张卡牌,每个人会发到k张卡牌,每个人都有一种喜欢的卡牌f[i],当一个 ...

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

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

  6. 999F Cards and Joy

    传送门 题目大意 有n个人n*m张牌,每个人分m张牌.每个人有一个自己喜欢的数值,如果他的牌中有x张数值等于这个值则他的高兴度为L[x],求怎样分配牌可以使得所有人的总高兴度最大. 分析 我们发现每一 ...

  7. Codeforces Round #490 (Div. 3)

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

  8. [Codeforces]Codeforces Round #490 (Div. 3)

    Mishka and Contest #pragma comment(linker, "/STACK:102400000,102400000") #ifndef ONLINE_JU ...

  9. BZOJ 1004 【HNOI2008】 Cards

    题目链接:Cards 听说这道题是染色问题的入门题,于是就去学了一下\(Bunside\)引理和\(P\acute{o}lya\)定理(其实还是没有懂),回来写这道题. 由于题目中保证"任意 ...

随机推荐

  1. jade 学习笔记 - gulp 自动编译

    实时监控   jade -P -w .\test1.jade sublime 分栏,可以看到实时修改情况     1. 元素写法 doctype html <!--[if IE8]>< ...

  2. [深度学习][图像处理][毕设][笔记][安装环境][下载地址]安装VS2013、matconvnet、cuda、cudnn过程中产生的一些记录,2018.5.6号

    最近半个多月,被cuda等软件折磨的死去活来,昨天下午,终于安装好了环境,趁着matlab正在,在线下载VOT2016数据集,3点睡眼惺忪被闹醒后,睡不着,爬上来写这份记录. 先记录一下自己电脑的基本 ...

  3. PowerMock学习之PoweMock的入门(二)

    前言 在上一篇<PowerMock学习之PoweMock的入门(一)>文章中,已经简单提及一些关于powermock的用法,但是入门还未完,我还要坚持把它学习并坚持更新到博客中. Mock ...

  4. iOS:应用程序扩展开发之Today扩展(Today Extesnsion)

    一.简介 iOS应用程序扩展是苹果在iOS8推出的一个新特性,可以将自定义的功能和内容扩展到应用程序之外,在之后又经过不断地优化和更新,已经成为开发中不可或缺的功能之一.扩展也是一个Target项目, ...

  5. C#怎么实现文件下载功能的四种方法

    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...

  6. 一分钟带你了解下MyBatis的动态SQL!

    MyBatis的强大特性之一便是它的动态SQL,以前拼接的时候需要注意的空格.列表最后的逗号等,现在都可以不用手动处理了,MyBatis采用功能强大的基于OGNL的表达式来实现,下面主要介绍下. 一. ...

  7. nyoj 204-Coin Test (python count)

    204-Coin Test 内存限制:64MB 时间限制:3000ms 特判: No 通过数:2 提交数:2 难度:1 题目描述: As is known to all,if you throw a ...

  8. Linq三表连接查询加分组

    1.Linq查询 2.数据库事例: 3.效果图:

  9. ArcGIS API For Javascript :如何在地图上做出点位脉冲闪烁的效果

    日常地图表达中我们通常使用的地图符号多是静态地图符号,时间久了会造成视觉审美疲劳,也没有现代感. 在这种背景下,对现有地图符号进行简单处理,即可得到色彩鲜艳,对比度强烈,活灵活现的地图表达形式. 灵感 ...

  10. windows版的mysql主从复制环境搭建

    背景 最近在学习用Spring Aop来实现数据库读写分离的功能. 在编写代码之前,首先是要部署好mysql的环境,因为要实现读写分离,所以至少需要部署两个mysql实例,一主一从,并且主从实例之间能 ...