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的更多相关文章

  1. 1371 - Energetic Pandas

    1371 - Energetic Pandas   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB ...

  2. bnu 51640 Training Plan DP

    https://www.bnuoj.com/bnuoj/problem_show.php?pid=51640 dp[i][j]表示前j个数,分成了i组,最小需要多少精力. 那么,求解订票dp[i][j ...

  3. \(\rm LightOJ 1371 - Energetic Pandas 简单计数+组合\)

    http://www.lightoj.com/volume_showproblem.php?problem=1371 题意:给你n根竹子,和n只熊猫(XD),每个熊猫只能选择重量不大于它的竹子,问有几 ...

  4. 树形dp - BNU 39572 Usoperanto

    Usoperanto Problem's Link Mean: 给定n个单词,每个单词可以作为形容词来修饰其他单词. 如果当前单词Wi修饰Wj,那么这个修饰的代价是:Wi~Wj之间的单词的总长度. 你 ...

  5. BNU 26349——Cards——————【区间dp】

    题目大意:给你n张牌,排成一排放在桌子上,可以从左端拿也可以从右端拿.现在有A,B两人轮流取牌,A先取,两人足够聪明,即都想取最大的牌总和,问A能取到的最大值. 解题思路:定义dp[i][j][k]. ...

  6. BNU 25593 Prime Time 记忆化dp

    题目链接:点击打开链接 题意: 一个游戏由3个人轮流玩 每局游戏由当中一名玩家选择一个数字作为開始 目的:获得最小的得分 对于当前玩家 O .面对 u 这个数字 则他的操作有: 1. 计分 u +1 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Laravel5.1学习笔记11 系统架构3 服务提供者

    服务提供者 简介 写一个服务提供者 Register注册方法 Boot 方法 注册提供者 缓载提供者 简介 Service providers are the central place of all ...

  2. 关于华为手机Log.d打印不出来log的问题

    http://blog.csdn.net/picasso_l/article/details/52489560     拨号,进入后台设置,进行操作.

  3. win32窗口映射(部分)

    先理解一下“窗口”与“视区”的概念.“窗口”是逻辑坐标下的矩形区域,“视区”是设备坐标系下的区域.根据“窗口”和“视区”的大小可以确定x方向和y方向的比例因子. 例子如下: VOID OnPaint( ...

  4. IOS7升级攻略

    1) Select the main view, set the background color to black (or whatever color you want the status ba ...

  5. php省市区三级联动

    效果 步骤 前端:通过ajax请求获取数据,使用了jquery 页面一开始加载所有省份信息 ->当选择省下拉框后触发改变监听时间-change ->当选择市下拉框后触发改变监听时间-cha ...

  6. JS数组reduce()方法

    1.语法 arr.reduce(callback,[initialValue]) reduce 为数组中的每一个元素依次执行回调函数,不包括数组中被删除或从未被赋值的元素,接受四个参数:初始值(或者上 ...

  7. Lua之尾调函数的用法

    Lua之尾调函数的用法 --当函数的最后返回结果调用另一个函数,称之为尾调函数 function f(x) return g(x) end --由于“尾调用”不会耗费栈空间,所以一个程序可以拥有无数嵌 ...

  8. pandas.DataFrame.quantile

    pandas.DataFrame.quantile 用于返回数据中的 处于1/5    1/2(中位数)等数据

  9. BZOJ 3572 [HNOI2014]世界树 (虚树+DP)

    题面:BZOJ传送门 洛谷传送门 题目大意:略 细节贼多的虚树$DP$ 先考虑只有一次询问的情况 一个节点$x$可能被它子树内的一个到x距离最小的特殊点管辖,还可能被管辖fa[x]的特殊点管辖 跑两次 ...

  10. Python 查看关键字

    关键字 import keyword print(keyword.kwlist)