BZOJ 4742: [Usaco2016 Dec]Team Building

4742: [Usaco2016 Dec]Team Building

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 21  Solved: 16
[Submit][Status][Discuss]

Description

Every year, Farmer John brings his NN cows to compete for "best in show" at the state fair. His arch

-rival, Farmer Paul, brings his MM cows to compete as well (1≤N≤1000,1≤M≤1000).Each of the N+MN+

M cows at the event receive an individual integer score. However, the final competition this year wi

ll be determined based on teams of KK cows (1≤K≤10), as follows: Farmer John and Farmer Paul both

select teams of KK of their respective cows to compete. The cows on these two teams are then paired

off: the highest-scoring cow on FJ‘s team is paired with the highest-scoring cow on FP‘s team, the s

econd-highest-scoring cow on FJ‘s team is paired with the second-highest-scoring cow on FP‘s team, a

nd so on. FJ wins if in each of these pairs, his cow has the higher score.Please help FJ count the n

umber of different ways he and FP can choose their teams such that FJ will win the contest. That is,

each distinct pair (set of KK cows for FJ, set of KK cows for FP) where FJ wins should be counted.

Print your answer modulo 1,000,000,009.

每年农夫约翰都会带着他的N只牛去集会上参加“你是最棒哒“的比赛。他的对手农夫保罗也带了M只牛去参加比赛

(1 ≤ N ≤ 1000, 1 ≤ M ≤ 1000)。每只牛都有自己的分数。两人会选择K只牛组成队伍(1 ≤ K ≤ 10),两队

牛在按分数大小排序后一一配对,并且约翰打败保罗当且仅当对于每一对牛,约翰的牛分数都比保罗的高。请帮助

约翰计算约翰打败保罗的方案数 mod 1000000009。两种方案不同,当且仅当约翰或保罗选择的牛的集合与另一种

方案不同。

Input

The first line of input contains N, M, and K. The value of K will be no larger than N or M.

The next line contains the N scores of FJ‘s cows.

The final line contains the M scores of FP‘s cows.

Output

Print the number of ways FJ and FP can pick teams such that FJ wins, modulo 1,000,000,009.

Sample Input

10 10 3
1 2 2 6 6 7 8 9 14 17
1 3 8 10 10 16 16 18 19 19

Sample Output

382

HINT

Source

Platinum 鸣谢Firstlast提供译文

[Submit][Status][Discuss]

看到网上还没有人写题解,来抢百度的沙发好了(不知道抢的抢不上)。

就是一道水水的动态规划了:首先得给两个序列分别排个序,$f[i][j][k]$表示使用FJ的前i头牛,以及FP的前j头牛,组出k头牛的战斗序列的方案数。$f[i][j][k]$向$f[i+1][j][k]$和$f[i][j+1][k]$转移,分别代表不选择FJ的第i头牛以及不选择FP的第j头牛,$f[i][j][k]$向$f[i+1][j+1][k+1]$转移当且仅当FJ的第i+1头牛能胜过FP的第j+1头牛。发现$f[i+1][j][k]$和$f[i][j+1][k]$向$f[i+1][j+1][k]$都有转移,而事实上这两次转移的方案是一样的,简言之,算重了,咋办,减掉就好,所以$f[i+1][j+1][k]-=f[i][j][k]$。

 1 #include <cstdio>
 2 #include <algorithm>
 3
 4 inline int nextChar(void) {
 5     const int siz = 1024;
 6
 7     static char buf[siz];
 8     static char *hd = buf + siz;
 9     static char *tl = buf + siz;
10
11     if (hd == tl)
12         fread(hd = buf, 1, siz, stdin);
13
14     return *hd++;
15 }
16
17 inline int nextInt(void) {
18     register int ret = 0;
19     register int neg = false;
20     register int bit = nextChar();
21
22     for (; bit < 48; bit = nextChar())
23         if (bit == ‘-‘)neg ^= true;
24
25     for (; bit > 47; bit = nextChar())
26         ret = ret * 10 + bit - 48;
27
28     return neg ? -ret : ret;
29 }
30
31 const int siz = 1005;
32 const int mod = 1000000009;
33
34 int n, m, d;
35
36 int a[siz];
37 int b[siz];
38
39 int f[siz][siz][15];
40
41 inline void add(int &a, int b)
42 {
43     a += b;
44
45     if (a >= mod)
46         a -= mod;
47
48     if (a < 0)
49         a += mod;
50 }
51
52 signed main(void)
53 {
54     n = nextInt();
55     m = nextInt();
56     d = nextInt();
57
58     for (int i = 1; i <= n; ++i)
59         a[i] = nextInt();
60
61     for (int i = 1; i <= m; ++i)
62         b[i] = nextInt();
63
64     std::sort(a + 1, a + 1 + n);
65     std::sort(b + 1, b + 1 + m);
66
67     f[0][0][0] = 1;
68
69     for (int i = 0; i <= n; ++i)
70         for (int j = 0; j <= m; ++j)
71             for (int k = 0; k <= d; ++k)
72                 if (f[i][j][k])
73                 {
74                     add(f[i + 1][j][k], f[i][j][k]);
75                     add(f[i][j + 1][k], f[i][j][k]);
76                     add(f[i + 1][j + 1][k], -f[i][j][k]);
77
78                     if (a[i + 1] > b[j + 1])
79                         add(f[i + 1][j + 1][k + 1], f[i][j][k]);
80                 }
81
82     printf("%d\n", f[n][m][d]);
83 }

@Author: YouSiki

时间: 2024-08-01 10:33:10

BZOJ 4742: [Usaco2016 Dec]Team Building的相关文章

BZOJ4742 : [Usaco2016 Dec]Team Building

如果我们将两个人拥有的牛混在一起,并按照战斗力从小到大排序,同时把第一个人选的牛看成$)$,第二个人选的牛看成$($的话,那么我们会发现一个合法的方案对应了一个长度为$2k$的括号序列. 于是DP即可,$f[i][j][k]$表示考虑了前$i$头牛,目前选了$j$个左括号,括号序列的前缀和为$k$的方案数. 时间复杂度$O(nk^2)$. #include<cstdio> #include<algorithm> const int N=2010,M=13,P=1000000009;

BZOJ 4576: [Usaco2016 Open]262144

Description 一个序列,每次可以将两个相同的数合成一个数,价值+1,求最后最大价值 \(n \leqslant 262144\) Sol DP. 这道题是 BZOJ 4580: [Usaco2016 Open]248 加强版. 做248的那个区间DP其实很多方案都是0,而且一个区间中只有一个合法的数字. 然后就是 一个区间合成一个数的方案的这个数字是固定的. \(f[i][j]\) 表示以 \(i\) 结尾是否能合成 \(j\),同时记录一下转移位置,每次向前找前一个指针就可以了. 复

bzoj4745: [Usaco2016 Dec]Cow Checklist

bzoj4745: [Usaco2016 Dec]Cow Checklist Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1  Solved: 1[Submit][Status][Discuss] Description Every day, Farmer John walks through his pasture to check on the well-being of each of his cows. Onh is farm he h

bzoj 1626: [Usaco2007 Dec]Building Roads 修建道路 -- 最小生成树

1626: [Usaco2007 Dec]Building Roads 修建道路 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer John最近得到了一些新的农场,他想新修一些道路使得他的所有农场可以经过原有的或是新修的道路互达(也就是说,从任一个农场都可以经过一些首尾相连道路到达剩下的所有农场).有些农场之间原本就有道路相连. 所有N(1 <= N <= 1,000)个农场(用1..N顺次编号)在地图上都表示为坐标为(X_i,

BZOJ 1626: [Usaco2007 Dec]Building Roads 修建道路( MST )

计算距离时平方爆了int结果就WA了一次...... ----------------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<cmath

[BZOJ] 1626: [Usaco2007 Dec]Building Roads 修建道路

1626: [Usaco2007 Dec]Building Roads 修建道路 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1724  Solved: 725[Submit][Status][Discuss] Description Farmer John最近得到了一些新的农场,他想新修一些道路使得他的所有农场可以经过原有的或是新修的道路互达(也就是说,从任一个农场都可以经过一些首尾相连道路到达剩下的所有农场).有些农场之间原本就有道路相连. 所

BZOJ 1626: [Usaco2007 Dec]Building Roads

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1626 赤裸裸的最次生成树,已有的边赋为0就好了,我用了prim(因为不熟) 不过有个神坑点,算坐标中乘法会超出int范围,所以在里面也要转为double(当然不排除你一开始用的就是long long) 程序: #include<iostream> #include<cstdio> #include<cmath> #define INF 2100000000.0

bzoj 1626: [Usaco2007 Dec]Building Roads 修建道路【最小生成树】

先把已有的边并查集了,然后MST即可 记得开double #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; const int N=1005; int n,m,f[N],con,tot; double x[N],y[N],ans; struct qwe { int u,v; double w; }e[N*N]; bool c

BZOJ 3389: [Usaco2004 Dec]Cleaning Shifts安排值班

题目 3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec  Memory Limit: 128 MB Description 一天有T(1≤T≤10^6)个时段.约翰正打算安排他的N(1≤N≤25000)只奶牛来值班,打扫 打扫牛棚卫生.每只奶牛都有自己的空闲时间段[Si,Ei](1≤Si≤Ei≤T),只能把空闲的奶牛安排出来值班.而且,每个时间段必需有奶牛在值班.  那么,最少需要动用多少奶牛参与值班呢?如果没有办法安排出合理的