2017ecjtu-summer training #6 Gym 100952D
1 second
256 megabytes
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 题意 一共有n件礼物,m个朋友,k个好朋友,好朋友的礼物必须超过d 给出n个礼物的价格(都不相同),问选择方案有多少?
解析 组合数学 令价格大于等于d的数量为sum c[sum][k]*c[n-k][m-k], 显然是错误的,因为会有好多重复的组合,
比如 (100 150 300 50 55)和(100 55 50 150 300)是重复的。
所以 应该是分步 分类(price >= d 的与 < d 的分开算, 这样就不会相同的礼物选2次了)
首先 C[sum][k] * C[n - sum][m - k];
然后 C[sum][k + 1] * C[n - sum][ m - k - 1];
接着 C[sum][k + 2] * C[n - sum][ m - k - 2];
......
一直循环到 i<=m&&i<=sum (看代码)
AC代码
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#define maxn 210
#define mod 1000000007
using namespace std;
typedef long long ll;
ll c[maxn][maxn];
int a[maxn];
void yanghui() //杨辉三角求C几几;
{
memset(c,,sizeof(c));
int i,j;
for(i=;i<maxn;i++)
c[i][]=;
for(i=;i<maxn;i++)
{
for(j=;j<=i;j++)
{
c[i][j]=(c[i-][j-]+c[i-][j])%mod;
}
}
}
int main()
{
int t;
int i,j;
int n,m,k,d;
yanghui();
cin>>t;
while(t--)
{
cin>>n>>m>>k>>d;
int sum=;
ll ans=;
for(i=;i<n;i++)
cin>>a[i];
sort(a,a+n);
for(i=;i<n;i++)
{
if(a[i]>=d)
{
sum++;
}
}
for(i=k;i<=m&&i<=sum;i++)
{
ans=(ans+c[sum][i]*c[n-sum][m-i])%mod;
}
cout<<ans<<endl;
}
}
2017ecjtu-summer training #6 Gym 100952D的更多相关文章
- 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 100952 D. Time to go back(杨辉三角形)
D - Time to go back Gym - 100952D http://codeforces.com/gym/100952/problem/D D. Time to go back time ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- Gym 101047K Training with Phuket's larvae
http://codeforces.com/gym/101047/problem/K 题目:给定n<=2000条绳子,要你找出其中三条,围成三角形,并且要使得围成的三角形面积最小 思路: 考虑一 ...
- Gym - 100676G Training Camp (状压dp)
G. Training Camp[ Color: Yellow ]Montaser is planning to train very hard for ACM JCPC 2015; he has p ...
- Gym - 100162G 2012-2013 Petrozavodsk Winter Training Camp G. Lyndon Words 暴力枚举
题面 题意:如果一个字符串的最小表示法是他自己,他就是一个Lyndon Word. 例如 aabcb 他的循环串有 abcba bcbaa cbaab baabc 其中字典序最小的是他自己 现在给 ...
- Gym 101915
Gym - 101915A Printing Books 题意:有一本书,从第X页开始,一共用了n位数字,求此书一共多少页.99就是两位数字,100就是三位数字. 思路:直接模拟即可,我用了一个hi ...
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- Gym - 100283F F. Bakkar In The Army —— 二分
题目链接:http://codeforces.com/gym/100283/problem/F F. Bakkar In The Army time limit per test 2 seconds ...
随机推荐
- iOS Swift--UIImageView UIImage
1.UIImageView + UIImage Demo import UIKit class UIImageViewViewController: UIViewController { var ...
- ABP .Net Core 部署到IIS 问题汇总
在ABP官网创建一个.Net Core项目编译完成 1. 发布网站 2. IIS新建站点 目录指向发布的目录 3.安装WindowsHosting IIS安装服务器上安装DotNetCore.X.X. ...
- vue使用国际化
转载请注明作者与出处 一:安装vue-i18n npm install vue-i18n --save 二:定义不同语言的json语言包 一般把它放到npm工程中的src目录下,因为这个目录是要进行编 ...
- Java I/O---Properties类(持久化键值对)
1.Properties类简介 Properties类(Java.util.Properties),主要用于读取Java的配置文件,各种语言都有自己所支持的配置文件,配置文件中很多变量是经常改变的,这 ...
- spring boot + Thymeleaf开发web项目
"Spring boot非常适合Web应用程序开发.您可以轻松创建自包含的HTTP应用.web服务器采用嵌入式Tomcat,或者Jetty等.大多数情况下Web应用程序将使用 spring- ...
- Windows as a Service(1)—— Windows 10服务分支
前言 作为公司的IT管理员,管理全公司Windows 10操作系统的更新一直是工作中的头疼之处.微软提供了很多方法来帮助我们管理公司的Windows 10更新,比如Windows Server Upd ...
- fdisk 命令详解
fdisk 作用: 查看磁盘实体使用情况,也可对硬盘分区. 选项: -b 分区大小 -l 列出指定的外围设备的分区表状况 -s 分区编号, 将指定的分区大小输出到标准输出上, 单位为区块 -u ...
- Webpack 2 视频教程 019 - Webpack 2 中配置多页面编译
原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」. Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本讲 ...
- 关于php中,记录日志中,将数组转为json信息记录日志时遇到的问题总结
1 中文编码化,无法看到具体的中文,如:你好 => \u4F60\u597D 解决方案:可以使用 json_encode($arr,JSON_UNESCAPED_UNICODE) 转义中文[ ...
- Xamarin调用JSON.net来解析JSON
https://www.cnblogs.com/zjoch/p/4458516.html 再来我们要怎么解析JSON格示呢?在.net 中,我们很孰悉的JSON.net,没错,我们依然可以在X ...