BNU 13289 Energetic Pandas DP
Energetic Pandas
There are n bamboos of different weights Wi. There are n pandas of different capacity CAPi. How many ways the pandas can carry the bamboos so that each panda carries exactly one bamboo, every bamboo is carried by one panda and a panda cannot carry a bamboo that is heavier than its capacity. Two ways will be considered different if at least one panda carries a different bamboo.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing an integer n (1 ≤ n ≤ 1000) denoting the number of pandas and bamboos. The next line contains n space separated distinct integers denoting the weights of be bamboos. The next line contains n space separated distinct integers denoting the capacities for the pandas. The weights and the capacities lie in the range [1, 109].
Output
For each case, print the case number and the number of ways those pandas can carry the bamboos. This number can be very big. So print the result modulo 1000 000 007.
Sample Input
Sample Input |
Output for Sample Input |
|
3 5 1 2 3 4 5 1 2 3 4 5 2 1 3 2 2 3 2 3 4 6 3 5 |
Case 1: 1 Case 2: 0 Case 3: 4 |
题意:给你n个容器,n个物品,每个人容器物品对应一个大小,容器大于等于才可将这个物品放入容器中,物品保证每个容器都放一个物品的情况下,问你方案数是多少
题解: 考虑前i个容器有多少个可以放第i个物品为 num,
则dp[i]表示前i个物品放完的方案数,dp[i]=dp[i-1]*(num)
可以预处理出可以放几个
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=;
const int Mod=;
int a[],b[],dp[];
int main()
{
int T;
scanf("%d",&T);
for(int ca=;ca<=T;ca++)
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
for(int i=;i<=n;i++)
scanf("%d",&b[i]);
sort(a+,a+n+);
sort(b+,b+n+);
dp[]=;
for(int i=;i<=n;i++)
{
int cnt=;
for(int j=;j<=i;j++)
cnt+=(b[j]>=a[i]);
dp[i]=1LL*cnt*dp[i-]%Mod;
}
printf("Case %d: %d\n",ca,dp[n]);
}
return ;
}
Q神
///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a)); inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//****************************************
const double PI = 3.1415926535897932384626433832795;
const double EPS = 5e-;
#define maxn 1000+5
#define mod 1000000007 int a[maxn],b[maxn],tmp[maxn],n;
int main() {
int T=read(),oo=;
while(T--) {
scanf("%d",&n);
for(int i=;i<=n;i++) {
scanf("%d",&a[i]);
}
for(int i=;i<=n;i++) {
scanf("%d",&b[i]);
}
sort(a+,a+n+);
sort(b+,b+n+);
int j=;bool flag=;
for(int i=;i<=n;i++) {
while(b[i]>=a[j]&&j<=n) {
j++;
}
j--;tmp[i]=j;
if(tmp[i]<i) {
flag=;
}
}printf("Case %d: ",oo++);
if(flag){
cout<<""<<endl;continue;
}ll dp[maxn];mem(dp);
for(int i=;i<=n;i++) {
if(i==)
dp[i]=tmp[];
else {
if(tmp[i]==i) {
dp[i]=dp[i-];
}
else {
dp[i]=dp[i-]*(tmp[i]-tmp[i-])%mod;
if(tmp[i-]>i-) dp[i]=(dp[i]+dp[i-]*(tmp[i-]-i+))%mod;
}
}
}
cout<<dp[n]<<endl;
}
return ;
}
蒟蒻
BNU 13289 Energetic Pandas DP的更多相关文章
- 1371 - Energetic Pandas
1371 - Energetic Pandas PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB ...
- bnu 51640 Training Plan DP
https://www.bnuoj.com/bnuoj/problem_show.php?pid=51640 dp[i][j]表示前j个数,分成了i组,最小需要多少精力. 那么,求解订票dp[i][j ...
- \(\rm LightOJ 1371 - Energetic Pandas 简单计数+组合\)
http://www.lightoj.com/volume_showproblem.php?problem=1371 题意:给你n根竹子,和n只熊猫(XD),每个熊猫只能选择重量不大于它的竹子,问有几 ...
- 树形dp - BNU 39572 Usoperanto
Usoperanto Problem's Link Mean: 给定n个单词,每个单词可以作为形容词来修饰其他单词. 如果当前单词Wi修饰Wj,那么这个修饰的代价是:Wi~Wj之间的单词的总长度. 你 ...
- BNU 26349——Cards——————【区间dp】
题目大意:给你n张牌,排成一排放在桌子上,可以从左端拿也可以从右端拿.现在有A,B两人轮流取牌,A先取,两人足够聪明,即都想取最大的牌总和,问A能取到的最大值. 解题思路:定义dp[i][j][k]. ...
- BNU 25593 Prime Time 记忆化dp
题目链接:点击打开链接 题意: 一个游戏由3个人轮流玩 每局游戏由当中一名玩家选择一个数字作为開始 目的:获得最小的得分 对于当前玩家 O .面对 u 这个数字 则他的操作有: 1. 计分 u +1 ...
- BNU 13064 Dice (I) 前缀和优化DP
Dice (I) You have N dices; each of them has K faces numbered from 1 to K. Now you have arranged th ...
- BNU 13024 . Fi Binary Number 数位dp/fibonacci数列
B. Fi Binary Number A Fi-binary number is a number that contains only 0 and 1. It does not conta ...
- bnuoj 34985 Elegant String DP+矩阵快速幂
题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 We define a kind of strings as elegant s ...
随机推荐
- fresh_bank、、
最近新学习了一个bank系统来和大家分享一下,新人求罩! 破索式之_链子枪_ 废话不多说了直接本主题 如果我们要写出bank系统,就要先考虑这个问题:总共需要几个类? 既然是银行系统,那么必不可少的就 ...
- Laravel5.1学习笔记11 系统架构3 服务提供者
服务提供者 简介 写一个服务提供者 Register注册方法 Boot 方法 注册提供者 缓载提供者 简介 Service providers are the central place of all ...
- vue项目杂记
vue项目杂记 文件目录结构 src main.js app.vue package.json webpack_config_dev.js 需要安装的包 1. vue cnpm i vue --sav ...
- Android传递中文参数方法(之一)
最近在做app,用的volley传参,有一个地方传中文参数不行(貌似是get方式),我又试了下post方式,成功了,记录下,以后有用! RequestQueue requestQueue = Voll ...
- React Native常用组件在Android和IOS上的不同
React Native常用组件在Android和IOS上的不同 一.Text组件在两个平台上的不同表现 1.1 height与fontSize 1.1.1只指定font,不指定height 在这种情 ...
- IP访问频率限制不能用数组循环插入多个限制条件原因分析及解决方案
14.IP频率限制不能用数组循环插入多个限制条件原因分析及解决方案: define("RATE_LIMITING_ARR", array('3' => 3, '6' => ...
- 使用TFS創建團隊項目
使用微軟賬號登錄Team Service,關聯一個TS賬戶,用來存放你所有的項目,可以從瀏覽器中直接訪問,地址類似yourname.visualstudio.com. 詳細鏈接 在TS賬戶主面板中,可 ...
- (转)Hibernate框架基础——cascade属性
http://blog.csdn.net/yerenyuan_pku/article/details/52760010 我们以部门和员工的关系为例讲解一对多关联关系映射时,删除部门时,如果部门有关联的 ...
- 网络编程_socketserver
一.socketserver 网络编程 1.socketserver支持多用户并发处理:2.socketserver是对socket的再封装;处理步骤:1.创建一个socketserver类2.继承B ...
- Mybatis操作Mysql批量更新的一个坑-&allowMultiQueries=true允许批量更新
前言 利用Mybatis批量更新或者批量插入,实际上即使Mybatis完美支持你的sql,你也得看看你操作的数据库是否完全支持,而同事,最近就遇到这样的一个坑! 问题 先带大家来 ...