Gym 100952 D. Time to go back
2017-07-18 10:46
309 查看
http://codeforces.com/gym/100952/problem/D
D. Time to go back
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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?
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.
Examples
Input
Output
D. Time to go back
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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?
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.
Examples
Input
2 5 3 2 100 150 30 100 70 10 10 5 3 50 100 50 150 10 25 40 55 300 5 10
Output
3 126 商店有n件商品,有m个朋友。其中又有k个十分亲密的朋友,十分亲密的朋友的礼物价值不得低于d,显然是一个排列组合,但数据量大,构造组合函数精度容易出问题,因此可以用杨辉三角 vis[i][j]=vis[i-1][j-1]+vis[i-1][j];
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <cmath> #include <map> #include <vector> #include <algorithm> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define PI 3.141592653589793238462 #define INF 0x3f3f3f3f3f #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; ll vis[210][210],val[210],n,m,k,d,t; bool cmp(int a,int b) { return a>b; } int main() { mem(vis); 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; } } scanf("%lld",&t); while(t--) { ll ans=0,pos=0; scanf("%lld%lld%lld%lld",&n,&m,&k,&d); for(ll i=0;i<n;i++) scanf("%lld",&val[i]); sort(val,val+n,cmp); for(ll i=0;i<n;i++) { if(val[i]>=d) ans++; else break; } if(n-ans==0) pos=vis[ans][m]; else if(ans<k || n<m) pos=0; else { for(ll i=k;i<=ans;i++) { if(m-i<0) break; pos=(pos+(vis[ans][i]*vis[n-ans][m-i])%MOD)%MOD; } } printf("%lld\n",pos); } }
相关文章推荐
- Gym 100952D&&2015 HIAST Collegiate Programming Contest D. Time to go back【杨辉三角预处理,组合数,dp】
- First time to go to church
- 328. Not to advance is to go back. 不进则退
- Go语言学习之time包(获取当前时间戳等)(the way to go)
- 有关mov [LABEL_GO_BACK_TO_REAL+3], ax
- Change from UTC time back to local time?
- How I Turned Down $300,000 from Microsoft to go Full-Time on GitHub
- Best time to go to see Dubai
- Go back to past
- ISO 8601: Delphi way to convert XML date and time to TDateTime and back (via: Stack Overflow)
- Shareoint 2013 APP Store添加APP时报错“Everything is fine, but we had a small problem getting your license. Please go back to the SharePoint Store to get t”
- it's time go to sleep ,i will be continue!
- Go Back To Lab
- Go Back To Paradise
- How I Turned Down $300,000 from Microsoft to go Full-Time on GitHub
- How I Turned Down $300,000 from Microsoft to go Full-Time on GitHub
- Git Step By Step - Step 2: Go Back in Time
- Go convert string to time
- Open Baidu webpage and type in Chinese characters to start searching, press “Back” button to go to B
- go home(4)-xi'an for benben & back to shanghai