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 ...
随机推荐
- OPP的三大特征之封装总结
'''封装: 1.什么是封装? 封装是把什么东西装到容器中,再封闭起来 与隐藏有相似之处,但不是单纯的隐藏 官方解释:封装是指对外部隐藏实现细节,并提供简单的使用接口 封装的好处: 1.提高安全性 2 ...
- 你真的懂JavaScript基础类型吗
夯实Javascript基础. 基本类型有六种: null,undefined,boolean,number,string,symbol. 基本类型的值是保存在栈内存中的简单数据段 基础类型特性 基础 ...
- 弹性布局--flex方向
flex方向 flex方向由flex-direction特性决定,用于定义弹性布局模式.flex-direction共有4种模式:从左向右.从右向左.从上往下.从下往上. 主轴 主轴的起点与终点定义了 ...
- <自动化测试方案_7>第七章、PC端UI自动化测试
第七章.PC端UI自动化测试 UI自动化测试又分为:Web自动化测试,App自动化测试.微信小程序.微信公众号UI层的自动化测试工具非常多,比较主流的是UFT(QTP),Robot Framework ...
- python使用rabbitMQ介绍一(生产-消费者模式)
1 模式介绍 生产者-消费者模式是最简单的使用模式. 一个生产者P,给队列发送消息,一个消费者C来取队列的消息. 这里的队列长度不限,生产者和消费者都不用考虑队列的长度. 队列的模型图: 2 示例代码 ...
- DIY手机锂电池万能充
今天翻出来一个诺基亚的旧手机,试了一下,无法开机,应该了电池亏电了.可惜手头没有充电器,无法给手机充电. 活人岂能让尿憋死?回想了一下以前用过的手机万能充的样式(这里暴露年龄了) 根据家中现成的材料, ...
- linux系统mysql-5.7 修改字符集
起因:我在网上看修改mysql字符的文章时,都说配置/etc/mysql/my.cnf文件 然而我打开我上述的my.cnf文件时,发现里面的内容跟别人的不一样,我就觉得这个肯定不是正确的文件 经过我在 ...
- Linux命令大杂烩
查看linux出口IP curl ifconfig.me scp跨服务器转移文件命令 scp 文件 root@IP:/application/apache-tomcat-8.0.36 回车, ...
- [LeetCode] 19. 删除链表的倒数第N个节点
题目链接:https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/ 题目描述: 给定一个链表,删除链表的倒数第 n 个节点, ...
- 一脸懵逼学习Storm---(一个开源的分布式实时计算系统)
Storm的官方网址:http://storm.apache.org/index.html 1:什么是Storm? Storm是一个开源的分布式实时计算系统,可以简单.可靠的处理大量的数据流.被称作“ ...