Gym 100952 D. Time to go back(杨辉三角形)
D - Time to go back
http://codeforces.com/gym/100952/problem/D
1 second
256 megabytes
standard input
standard output
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?
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.
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.
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 题意:T组样例,每组样例第一行n个价格,m个好友,k个亲密好友,亲密好友最小的价格是d,第二行是这n个价格
思路:就是排列组合嘛,关键是求组合数,在这里我开始的话是写了一个函数求,最后发现过不了,因为数据太大,精度会出现问题,所以我们要用到杨辉三角形
yanghui[i][j]=(vis[i-1][j-1])+((vis[i-1][j])
代码如下:
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int a[205];
#define MOD 1000000007
long long sum,vis[210][210];
int aa(int n,int m)
{
if(m==0)
return 1;
int s=1,g=1;
for(int i=n;i>=n-m+1;i--)
s*=i;
for(int i=1;i<=m;i++)
g*=i;
return s/g;
}
int main()
{
for(int i=0;i<210;i++)
{
vis[i][0]=1;
for(int j=1;j<=i;j++)
{
vis[i][j]=(((vis[i-1][j-1])%MOD)+((vis[i-1][j])%MOD))%MOD;
}
}
int t;
cin>>t;
while(t--)
{
int n,m,k,d,xia=0,shang=0;
cin>>n>>m>>k>>d;
memset(a,0,sizeof(a));
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]>=d)
xia++;
else
shang++;
}
int i=0;
sum=0;
while(xia-i>=k)
{
if(m-xia+i>=0)
{
sum=(sum+(vis[xia][xia-i]*vis[shang][m-xia+i])%MOD)%MOD; }
i++;
}
cout<<sum<<endl;
}
}
Gym 100952 D. Time to go back(杨辉三角形)的更多相关文章
- codeforces gym 100952 A B C D E F G H I J
gym 100952 A #include <iostream> #include<cstdio> #include<cmath> #include<cstr ...
- Gym 100952 H. Special Palindrome
http://codeforces.com/gym/100952/problem/H H. Special Palindrome time limit per test 1 second memory ...
- Gym 100952 G. The jar of divisors
http://codeforces.com/gym/100952/problem/G G. The jar of divisors time limit per test 2 seconds memo ...
- Gym 100952 F. Contestants Ranking
http://codeforces.com/gym/100952/problem/F F. Contestants Ranking time limit per test 1 second memor ...
- Gym 100952 D. Time to go back
http://codeforces.com/gym/100952/problem/D D. Time to go back time limit per test 1 second memory li ...
- Gym 100952 C. Palindrome Again !!
http://codeforces.com/gym/100952/problem/C C. Palindrome Again !! time limit per test 1 second memor ...
- Gym 100952 A. Who is the winner?
A. Who is the winner? time limit per test 1 second memory limit per test 64 megabytes input standard ...
- Gym 100952 B. New Job
B. New Job time limit per test 1 second memory limit per test 64 megabytes input standard input outp ...
- 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 ...
随机推荐
- 小K的H5之旅-CSS基础(一)
一.什么是CSS W3C标准中,倡导有3:其一为内容与表现分离,其二为内容与行为分离,其三为内容结构的语义化.其倡导中第一条的"表现"指的便可以说是CSS.CSS全称Cascadi ...
- Hadoop化繁为简(二)—层层递进轻松入门hdfs
层层递进-解开hdfs的面纱 1.hdfs是什么?它与普通服务器的文件系统有什么区别?它的特性有什么? 2.hdfs的工作原理是怎样的? 3.每台机器都单独启动有什么弊端?假设有1000台机器需要启动 ...
- 网页中使用CSS和JS阻止用户选择内容
CSS实现 body{ -webkit-user-select:none; -moz-user-select:none; -ms-user-select:none; user-select:none; ...
- dotnet 命令实战
以下用实例串起dotnet所有命令,带你玩转dotnet命令. 1.创建(dotnet new) 首先我们创建一个项目,这里我们创建控制台程序,命令如下图所示. dotnet new dotnet n ...
- CommonsChunkPlugin并不是分离第三方库的好办法(DllPlugin科学利用浏览器缓存)
webpack算是个磨人的小妖精了.之前一直站在glup阵营,使用browserify打包,发现webpack已经火到爆炸,深怕被社区遗落,赶紧拿起来把玩一下.本来只想玩一下的.尝试打包了以后,就想启 ...
- CentOS7安装使用Docker
安装 Docker 官方为了简化安装流程,提供了一套安装脚本,CentOS 系统上可以使用这套脚本安装: curl -sSL https://get.docker.com/ | sh 执行这个命令后, ...
- openvpn配置注意事项
1.安装VPN安装结束后,需要配置CONFIG文件夹服务端及客户端的配置文件,建议从sample文件里直接拷贝修改,网上的一些案例会引起无法启动的问题,没仔细研究过是哪里错了,反正最后从sample里 ...
- UWP的Converter妙用
MVVM模式的使用,简化了UWP应用的开发,使层次更加分明.在写xaml的时候,有些小技术还是很实用的:比如Converter,字面上理解是转换器,那它到底是转换什么的?接触过的可能知道它起的是类型转 ...
- 浅尝JavaScript document对象
document对象 每个载入浏览器的 HTML 文档都会成为 Document 对象.document 对象是HTML文档的根节点与所有其他节点(元素节点,文本节点,属性节点, 注释节点).Docu ...
- jQuery – 鼠标经过(hover)事件的延时处理
一.关于鼠标hover事件及延时 鼠标经过事件为web页面上非常常见的事件之一.简单的hover可以用CSS :hover伪类实现,复杂点的用js. 一般情况下,我们是不对鼠标hover事件进行延时处 ...