Gym - 101982C Contest Setting (动态规划)
A group of contest writers have written n problems and want to use k of them in an upcoming contest. Each problem has a difficulty level. A contest is valid if all of its k problems have different difficulty levels.
Compute how many distinct valid contests the contest writers can produce. Two contests are distinct if and only if there exists some problem present in one contest but not present in the other.
Print the result modulo 998,244,353.
Input
The first line of input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 1000)
The next line contains n space-separated integers representing the difficulty levels. The difficulty levels are between 1 and 109 (inclusive).
Output
Print the number of distinct contests possible, modulo 998,244,353.
Sample Input
5 2
1 2 3 4 5
Sample Output
10
题意:
选出k个难度不同的题,问有几种选法。
思路:
dp[i][j]表示从i种不同的题中选出j个不同的题的方法数。
当前题选的话,方法数是dp[i-1][j-1]*(当前难度题的个数)
当前题不选的话,方法数是dp[i-1][j].
dp[i][j]就是二者之和。
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
map<int,int>mp;
ll dp[][];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
ll ans=;
ll num=;
for(int i=;i<=n;i++){
int x;
scanf("%d",&x);
mp[x]++;
}
map<int,int>::iterator it=mp.begin();
int sz=mp.size();
for(int i=;i<=sz;i++){
dp[i][]=;
}
for(int i=;i<=sz;i++){
for(int j=k;j>=;j--){
dp[i][j]=dp[i-][j]+dp[i-][j-]*(it->second);
dp[i][j]%=mod;
}
it++;
}
printf("%lld\n",dp[sz][k]); }
Gym - 101982C Contest Setting (动态规划)的更多相关文章
- Contest Setting 2018 ICPC Pacific Northwest Regional Contest dp
题目:https://vj.69fa.cn/12703be72f729288b4cced17e2501850?v=1552995458 dp这个题目网上说是dp+离散化这个题目要对这些数字先处理然后进 ...
- 2018-2019 ACM-ICPC Pacific Northwest Regional Contest C Contest Setting(DP)
比赛链接:Contest Setting C题 题意:$n$道题目,每道题目难度为$ai$,选择$k$道难度不同的题目,有多少种选择方案.$1<=k<=n<=1000,1<=a ...
- C - Contest Setting Gym - 101982C dp 补题
题目链接:https://vjudge.net/contest/273260#problem/C 学习了一下别人的思路,首先去重,然后离散化. dp数组开二维,每一次更新,状态转移方程,dp[ i ] ...
- 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)
2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) 思路: A Exam 思路:水题 代码: #include<bits ...
- 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution
A:Exam Solved. 温暖的签. #include<bits/stdc++.h> using namespace std; ; int k; char str1[maxn], st ...
- HDUOJ-----I NEED A OFFER!
I NEED A OFFER! Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tot ...
- Gym 100952F&&2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+优先队列】
F. Contestants Ranking time limit per test:1 second memory limit per test:24 megabytes input:standar ...
- Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】
E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard inp ...
- 2019春季训练02: JU Flash Contest Gym - 102035 训练报告与复盘
这场题极其简单 Solved 19 / 19 A Gym 102035A N integers 略 Solved 10 / 33 B Gym 102035B Mahmoud the Thief 用ma ...
随机推荐
- Dynamics 365中显示格式为URL的字段极少部分URL值录入了不显示怎么回事?
微软动态CRM专家罗勇 ,回复318或者20190315可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . 对于如下类型的字段, ...
- ArcGIS API for JavaScript 与 npm 之例子运行
下载官方的demo,4.7的,在终端里跑了一下,测试成功(未打包) 在测试中精简掉了不需要的文件,使用http协议跑的(file协议不行哦) 最简单的目录如下: 我把以上文件放到一个叫demo的文件夹 ...
- win10下安装mysql5.7.25版本
之前使用mysql都是使用的xampp上面集成的mysql,也在安装过5.6.35的版本,好像都是下一步下一步就完成了,昨天安装了一个5.7.25的版本的mysql,也不知道怎么了,就开始百度一些东西 ...
- 关于LeetCode上链表题目的一些trick
最近在刷leetcode上关于链表的一些高频题,在写代码的过程中总结了链表的一些解题技巧和常见题型. 结点的删除 指定链表中的某个结点,将其从链表中删除. 由于在链表中删除某个结点需要找到该结点的前一 ...
- 『cURL』curl: (6) Could not resolve host无法解析主机地址
最近在学数据挖掘时,获取数据有两种途径: 开放数据,可以直接使用和存储的数据: 网络数据,通过爬虫或云市场api(付费或免费)获取数据 我通过教程,在阿里云购买一个天气数据api,尝试使用cURL获取 ...
- 教你在浏览器里做出EXCEL的效果
在浏览器里做出EXCEL的效果,复制.粘贴.设置公式.双击编辑等效果,如果自己开发的话,比较麻烦,建议使用成熟的插件.这里介绍使用智表ZCELL插件,实现用户快捷操作. 首先下载插件,引入到页面中,一 ...
- 如何保持Redis和MySQL数据一致
原文:https://blog.csdn.net/thousa_ho/article/details/78900563 1. MySQL持久化数据,Redis只读数据 redis在启动之后,从数据库加 ...
- 《你必须掌握的Entity Framework 6.x与Core 2.0》勘误
第5章 5.1.1----致谢网友[宪煌] public virtual ICollection Post {get;set;} 修改为 public virtual ICollection<P ...
- H5活动页开发有关
活动页开发流程 针对各种节日各种活动,临时定稿开发的活动页,往往时间安排都比较急 ---- 产品定下需求方向 UI实现设计稿 1. 草图和交互逻辑定稿=>多少个页面,每个页面表达的含义以及和用户 ...
- JS 设计模式七 -- 外观模式
概念 为子系统中的一组接口提供一个一致的界面,定义一个高层接口,这个接口使子系统更加容易使用. 外观模式在JS中,可以认为是一组函数的集合. 实现 // 三个处理函数 function start() ...