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 ...
随机推荐
- Unity学习-地形的设置(五)
添加地形游戏对象 [Hierarchy-Create-Terrain] 为了看的看清楚,在添加一个平行光 [Hierarchy-Create-Direction light] 导入地形包 [Asset ...
- JS高级——词法作用域
作用域 1.js中没有块级作用域 2.如果有块级作用域,那么下面代码将会是undefined undefined <script> for (var i = 0; i < 10; i ...
- CSS——float
float:就是在于布局,首先要介绍的是文档流(标准流),之后是浮动布局. 文档流:元素自上而下,自左而右,块元素独占一行,行内元素在一行上显示,碰到父集元素的边框换行. 浮动布局: 1.float: ...
- postgresql用sql语句查询表结构
用到的postgresql系统表 关于postgresql系统表,可以参考PostgreSQL 8.1 中文文档-系统表. pg_class 记录了数据库中的表,索引,序列,视图("关系&q ...
- css 众妙之门 学习笔记
伪类: 结构伪类: :empty :only-child :before :after :active :hover :focus :link :visited :first-child :last- ...
- @RequestMapping参数value和params的区别
value的值可以是一个url地址的形式或者正则表达式或者rest风格的形式,而params正如其名是参数,访问的时候params的值只能作为参数,不能作为访问的地址,请看下例> value的使 ...
- Centos6.7 安装zabbix+apache+mysql教程(第一篇)
Centos6.7 安装zabbix+apache+mysql教程 blog地址: http://www.cnblogs.com/caoguo ### 基本包安装 ### [root@ca0gu0 ~ ...
- jboss 虚拟路径
jboss 虚拟路径 上传文件到服务器时,保存到服务器发布应用外路径.这时,就要通过在jboss配置虚拟路劲以访问. 在standalong.xml里找到 <subsystem xmlns=&q ...
- PHP 之文件锁解决并发问题
一.参数说明 $handle: 文件资源 $operation: 锁的类型 LOCK_SH: 共享锁 LOCK_EX: 排他锁 LOCK_UN: 释放锁 $wouldblock: 设置为true的时候 ...
- .net core里用ZXing生成二维码
先获取Nuget包 static void Main(string[] args) { string content = "二维码信息"; BitMatrix byteMatrix ...