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 ...
随机推荐
- 简述UIDatePicker的用法
1.Locale 设置DatePicker的地区,即设置DatePicker显示的语言. 1.跟踪所有可用的地区,取出想要的地区 NSLog(@"%@", [NSLocale av ...
- Android基于HttpUrlConnection类的文件下载
/** * get方法的文件下载 * <p> * 特别说明 android中的progressBar是google唯一的做了处理的可以在子线程中更新UI的控件 * * @param pat ...
- 在mac上快捷找到nodejs的安装路径
打开控制台输入 which node ,得到的输出结果就是node安装路径
- 02--SQLite操作一步到位
SQLite数据库(一):基本操作 SQLite 是一个开源的嵌入式关系数据库,实现自包容.零配置.支持事务的SQL数据库引擎. 其特点是高度便携.使用方便.结构紧凑.高效.可靠. 与其他数据库管理系 ...
- C# 配置文件ini操作类
// [ DllImport ( "kernel32" ) ] //private static extern long WritePrivateProfileString ( s ...
- 2015.12.25-2016.01.01 大论文迭代B
大论文B轮迭代,稍重前端 12.25 周五,完善摘要 12.26 周六,完善第一章 12.27 周天,完善第二章 12.28 周一,完善第三章 12.29 周二,完善第四章 12.30 周三,完善第五 ...
- CWnd* pParent
Dlg(CWnd* pParent = NULL)的意思是:构造函数.创建对象时第一个调用的地方.CWnd* pParent=NULL是构造的参数,可以不传入,默认为NULL 构造函数(constru ...
- Java切换JDK版本的方法及技巧
由于项目的不同安排,之前项目开发时,使用的jdk版本为1.8,现临时接手一以前项目,需要更换jdk版本. 安装 不再赘述,去Oracle网站(https://www.oracle.com/techne ...
- SpringMVC与MyBatis整合方法
一.springmvc+mybaits的系统架构: 第一步:整合dao层 mybatis和spring整合,通过spring管理mapper接口. 使用mapper的扫描器自动扫描mapper接口在s ...
- SGU100
Read integers A and B from input file and write their sum in output file. Input Input file contains ...