列表

详情


NC24151. [USACO 2016 Dec P]Team Building

描述

Every year, Farmer John brings his N cows to compete for "best in show" at the state fair. His arch-rival, Farmer Paul, brings his M cows to compete as well (1≤N≤1000,1≤M≤1000).
Each of the N+M cows at the event receive an individual integer score. However, the final competition this year will be determined based on teams of K cows (1≤K≤10), as follows: Farmer John and Farmer Paul both select teams of K 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 second-highest-scoring cow on FJ's team is paired with the second-highest-scoring cow on FP's team, and so on. FJ wins if in each of these pairs, his cow has the higher score.

Please help FJ count the number of different ways he and FP can choose their teams such that FJ will win the contest. That is, each distinct pair (set of K cows for FJ, set of K cows for FP) where FJ wins should be counted. Print your answer modulo 1,000,000,009.

输入描述

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.

输出描述

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

示例1

输入:

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

输出:

382

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 60ms, 内存消耗: 43784K, 提交时间: 2020-09-20 10:55:35

// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=1000+10,M=10+10;
const int mod=1e9+9;

int n,m,k;
int a[N],b[N];
int dp[M][N][N];

int main() {
	n=read(),m=read(),k=read();
	for (int i=1;i<=n;++i) a[i]=read();
	for (int i=1;i<=m;++i) b[i]=read();
	sort(a+1,a+n+1),sort(b+1,b+m+1);
	for (int i=0;i<=n;++i)
		for (int j=0;j<=m;++j) dp[0][i][j]=1;
	for (int i=1;i<=k;++i) {
		for (int p=1;p<=n;++p)
			for (int q=1;q<=m;++q)
				if (a[p]>b[q]) dp[i][p][q]=dp[i-1][p-1][q-1];
		for (int p=1;p<=n;++p)
			for (int q=1;q<=m;++q)
				dp[i][p][q]=(dp[i][p][q]+dp[i][p][q-1])%mod;
		for (int p=1;p<=n;++p)
			for (int q=1;q<=m;++q)
				dp[i][p][q]=(dp[i][p][q]+dp[i][p-1][q])%mod;
	}
	printf("%d\n",dp[k][n][m]);
	return 0;
}

C++ 解法, 执行用时: 63ms, 内存消耗: 43640K, 提交时间: 2021-11-10 14:49:06

#include <bits/stdc++.h>
const int NN = 1004, mo = 1e9 + 9;
#define _forr(i, a, b) for (int i = (a); i <= (int)(b); ++i)
using namespace std;
int A[NN], B[NN], f[12][NN][NN];
int main() {
  int n, m, p;
  scanf("%d%d%d", &n, &m, &p);
  _forr(i, 1, n) scanf("%d", &A[i]);
  _forr(i, 1, m) scanf("%d", &B[i]);
  sort(A + 1, A + n + 1), sort(B + 1, B + m + 1);
  _forr(i, 0, n) _forr(j, 0, m) f[0][i][j] = 1;
  _forr(i, 1, p) {
    _forr(j, 1, n) _forr(k, 1, m) 
      if (A[j] > B[k]) f[i][j][k] = f[i - 1][j - 1][k - 1];
    _forr(j, 1, n) _forr(k, 1, m)(f[i][j][k] += f[i][j][k - 1]) %= mo;
    _forr(j, 1, n) _forr(k, 1, m)(f[i][j][k] += f[i][j - 1][k]) %= mo;
  }
  printf("%d", f[p][n][m]);
}

上一题