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 ...
随机推荐
- Zepto源码分析-ajax模块
源码注释 // Zepto.js // (c) 2010-2015 Thomas Fuchs // Zepto.js may be freely distributed under the MIT l ...
- javascript基础-BOM原理
图解: 1. Loction: 拼接参数时,应编码decodeURIComponent/encodeURIComponent(). 2. History: pushState+replaceStat ...
- 网络编程应用:基于UDP协议【实现文件下载】--练习
要求: 基于UDP协议实现文件下载 发送方–请求–接收方发送文件–发送方接收文件 代码: 发送方: package Homework1; import java.io.File; import jav ...
- web项目中url-pattern改成'/'后,js、css、图片等静态资源(404)无法访问问题解决办法
感谢http://blog.csdn.net/this_super/article/details/7884383的文章 1.增加静态资源url映射 如Tomcat, Jetty, JBoss, Gl ...
- Python的核心数据结构
数据结构 例子 数字 1234,3.1415,3+4j 字符串 'spam'."grace's" 列表 [1,[2,'three'],4] 字典 {'food':'spam','t ...
- String 类问题发现与解决
1.在代码中出现:String t = null; t.length(); 执行后:控制台报:java.lang.NullPointerException 原因:Java中,null是一个关键字,用来 ...
- react-native-fs插件的使用以及遇到的坑
react-native-fs插件是文件对上传和下载时使用的,iOS和android都可使用,File upload (iOS only). 安装命令: npm install react-nativ ...
- Laravel踩坑笔记——illuminate/html被抛弃
起因 在使用如下代码的时候发生报错 {!! Form::open() !!} 错误信息 [Symfony\Component\Debug\Exception\FatalErrorException] ...
- MVC之前-ASP.NET初始化流程分析1
Asp.net Mvc是当前使用比较多的web框架,也是比较先进的框架.我打算根据自己的实际项目经验以及相关的源码和一些使用Asp.net Mvc的优秀项目(主要是orchard)来说一说自己对于As ...
- 基于Angularjs实现图片上传和下载
根据ng-file-uoload实现文件上传和下载实现 网上down下来ng-file-uoload.js,在项目中记得引入服务哦. 示例代码: FileUploaderCtrl.$inject = ...