2015 HIAST Collegiate Programming Contest D
You have been out of Syria for a long time, and you recently decided to come back. You remember that you have M friends there and since you are a generous man/woman you want to buy a gift for each of them, so you went to a gift store that have N gifts, each of them has a price.
You have a lot of money so you don't have a problem with the sum of gifts' prices that you'll buy, but you have K close friends among your M friends you want their gifts to be expensive so the price of each of them is at least D.
Now you are wondering, in how many different ways can you choose the gifts?
Input
The input will start with a single integer T, the number of test cases. Each test case consists of two lines.
the first line will have four integers N, M, K, D (0 ≤ N, M ≤ 200, 0 ≤ K ≤ 50, 0 ≤ D ≤ 500).
The second line will have N positive integer number, the price of each gift.
The gift price is ≤ 500.
Output
Print one line for each test case, the number of different ways to choose the gifts (there will be always one way at least to choose the gifts).
As the number of ways can be too large, print it modulo 1000000007.
Example
2
5 3 2 100
150 30 100 70 10
10 5 3 50
100 50 150 10 25 40 55 300 5 10
3
126 解题思路:
就是一道很容易的高中排列组合题,放在高中是送分题,结果被卡到比赛结束。
有n个商品,要选m个送人,其中k各人要价格大于d的商品,问有多少种分法。 假设有10个人,送5个,3个要价格高的,
那么有三种情况:
1.贵的选三个,不贵的选两个:c53*c52
2.贵的选四个,不贵的选一个:c54*c51
3.贵的选五个:c55
分法就是 c53*c52+c54*c51+c55
之前写的时候一直不对,要用杨辉三角解,如果直接除的话,分子是很大的必须要取模,但取完模后,分子会小于分母,然后数值就为0,而杨辉三角就没有这种顾虑了,只有加法。。 实现代码:
#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9+;
#define ll long long
const int maxx = *1e2+;
ll mod(ll x){
return x-(x/inf)*inf;
} int main()
{
int i,j,n,m,k,d,a,t,cnt;
ll c[maxx][maxx],ans;
memset(c,,sizeof(c));
for(i=;i<maxx;i++){
c[i][] = ;
for(j=;j<=i;j++)
c[i][j] = mod(c[i-][j-]+c[i-][j]);
}
ios::sync_with_stdio();
cin.tie();
cin>>t;
while(t--){
ans = ;cnt=;
cin>>n>>m>>k>>d;
for(i=;i<n;i++){
cin>>a;
if(a>=d)
cnt++;
}
//cout<<ans<<endl;
for(i=k;i<=cnt;i++){
if(n-cnt==) break;
if(m-i<) break;
else
ans=mod(ans+mod(c[cnt][i]*c[n-cnt][m-i]));
//cout<<c[cnt][i]<<" "<<c[n-cnt][m-i]<<endl;
//cout<<ans<<endl;
}
if(n - cnt == ) ans = c[cnt][m];
//ans = mod(C[cnt][k] * C[n - k][m - k]);
if(cnt < k || n < m)
cout<<""<<endl;
else cout<<ans<<endl;
}
return ;
}
2015 HIAST Collegiate Programming Contest D的更多相关文章
- 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 ...
- 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 100952J&&2015 HIAST Collegiate Programming Contest J. Polygons Intersection【计算几何求解两个凸多边形的相交面积板子题】
J. Polygons Intersection time limit per test:2 seconds memory limit per test:64 megabytes input:stan ...
- Gym 100952I&&2015 HIAST Collegiate Programming Contest I. Mancala【模拟】
I. Mancala time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ou ...
- Gym 100952H&&2015 HIAST Collegiate Programming Contest H. Special Palindrome【dp预处理+矩阵快速幂/打表解法】
H. Special Palindrome time limit per test:1 second memory limit per test:64 megabytes input:standard ...
- Gym 100952G&&2015 HIAST Collegiate Programming Contest G. The jar of divisors【简单博弈】
G. The jar of divisors time limit per test:2 seconds memory limit per test:64 megabytes input:standa ...
- Gym 100952D&&2015 HIAST Collegiate Programming Contest D. Time to go back【杨辉三角预处理,组合数,dp】
D. Time to go back time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- Gym 100952C&&2015 HIAST Collegiate Programming Contest C. Palindrome Again !!【字符串,模拟】
C. Palindrome Again !! time limit per test:1 second memory limit per test:64 megabytes input:standar ...
- Gym 100952B&&2015 HIAST Collegiate Programming Contest B. New Job【模拟】
B. New Job time limit per test:1 second memory limit per test:64 megabytes input:standard input outp ...
- Gym 100952A&&2015 HIAST Collegiate Programming Contest A. Who is the winner?【字符串,暴力】
A. Who is the winner? time limit per test:1 second memory limit per test:64 megabytes input:standard ...
随机推荐
- 串口通信-MSComm控件使用详解
串口通信-MSComm控件使用详解 2012年11月13日 09:35:45 他山之石可以攻玉 阅读数:37952更多 个人分类: 控件编程Delphi编程 MSComm 控件通过串行端口传输和接 ...
- java算法----排序----(5)归并排序
package log; import java.util.Arrays; public class Test4 { /** * java算法---归并排序 * * @param args */ pu ...
- UOJ400/LOJ2553 CTSC2018 暴力写挂 边分治、虚树
传送门--UOJ 传送门--LOJ 跟隔壁通道是一个类型的 要求的式子中有两个LCA,不是很方便,因为事实上在这种题目中LCA一般都是枚举的对象-- 第二棵树上的LCA显然是动不了的,因为没有其他的量 ...
- Luogu2467 SDOI2010 地精部落 DP
传送门 一个与相对大小关系相关的$DP$ 设$f_{i,j,0/1}$表示放了$i$个,其中最后一个数字在$i$个中是第$j$大,且最后一个是极大值($1$)或极小值时($0$)的方案数.转移: $$ ...
- TiDB入门(四):从入门到“跑路”
前言 前面三章基本把 TiDB 的环境弄好了,也做了一下简单测试,有兴趣的同学可以看一下: TiDB 入门(一):TiDB 简介 TiDB 入门(二):虚拟机搭建 TiDB-Ansible 部署方案 ...
- [开源 .NET 跨平台 Crawler 数据采集 爬虫框架: DotnetSpider] [三] 配置式爬虫
[DotnetSpider 系列目录] 一.初衷与架构设计 二.基本使用 三.配置式爬虫 四.JSON数据解析与配置系统 五.如何做全站采集 上一篇介绍的基本的使用方式,自由度很高,但是编写的代码相对 ...
- 新人入坑Redis必会的吐血总结
新人入坑Redis必会的吐血总结 一.什么是Redis Redis是一个使用C语言开发的开源的高性能的key-value存储系统,我们可以把它近似理解为Java Map.简单来讲,Redis是一种NO ...
- Python - 列表解析式
列表解析——用来动态地创建列表 [expr for iter_var in iterable if cond_expr] 例子一: map(lambda x: x**2, range(6)) [0, ...
- Popush End
coconut: (咳咳)作为一名后台开发者,我觉得自己在这次作业完成中最大的收获就是跟node.js的异步模型打交道.首先我得出了一个这样的结论:异步模型能够提高服务器的高性能并发请求,但是却加大了 ...
- Rop框架学习笔记
1. 提供了开发服务平台的解决方案:比如应用认证.会话管理.安全控制.错误模型.版本管理.超时限制 2. 启动:RopServlet截获http请求 配置: <servlet> < ...