結果

問題 No.1214 Market
ユーザー leaf_1415leaf_1415
提出日時 2020-08-30 17:59:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,627 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 89,396 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 12:47:31
合計ジャッジ時間 3,691 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 6 ms
6,944 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 5 ms
6,944 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 2 ms
6,940 KB
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

const int FACT_MAX = 1005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

llint comb2(llint n, llint k)
{
	llint ret = 1;
	for(int i = 0; i < k; i++) ret *= n-i, ret %= mod;
	ret *= fact_inv[k], ret %= mod;
	return ret;
}

llint n, m, c;
llint a[45], b[45];
llint dp[45][45][45];
llint dp2[45][45];
llint mul[45];
vector<llint> vec;

llint get(llint L, llint k)
{
	llint ret = 0;
	for(int i = 0; i <= min(L, k); i++){
		ret += comb2(L, i) * dp2[i][k] % mod, ret %= mod;
	}
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	make_fact();
	
	cin >> n >> m >> c;
	for(int i = 1; i <= m; i++) cin >> a[i] >> b[i];
	
	dp2[0][0] = 1;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 1; k <= n; k++){
				dp2[i+1][j+k] += dp2[i][j] * fact_inv[k] % mod;
				dp2[i+1][j+k] %= mod;
			}
		}
	}
	/*for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			dp2[i][j] *= fact[j], dp2[i][j] %= mod;
		}
	}*/
	
	/*for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			cout << dp2[i][j] << " ";
		}
		cout << endl;
	}*/
	
	llint ans = 0;
	for(int i = 1; i <= m; i++){
		vec.clear();
		for(int j = 1; j <= m; j++){
			if(b[j] >= b[i] && a[j] >= a[i]) vec.push_back(a[j]);
		}
		vec.push_back(c+1);
		sort(vec.rbegin(), vec.rend());
		llint M = vec.size()-1;
		
		for(int j = 0; j <= M; j++){
			for(int k = 0; k <= n; k++){
				for(int l = 0; l <= n; l++){
					dp[j][k][l] = 0;
				}
			}
		}
		dp[0][0][0] = 1;
		
		for(int j = 0; j < M; j++){
			for(int k = 0; k <= n; k++) mul[k] = get(vec[j]-vec[j+1], k);
			//for(int k = 0; k <= n; k++) cout << mul[k] << " "; cout << endl;
			for(int k = 0; k <= n; k++){
				for(int l = 0; l <= n; l++){
					for(int s = 0; s <= n; s++){
						llint nl = l+s;
						if(j+1 < M) nl = max(0LL, nl-1);
						if(k+s <= n && nl <= n){
							(dp[j+1][k+s][nl] += dp[j][k][l] * mul[s] % mod) %= mod;
						}
					}
				}
			}
		}
		
		/*for(int k = 0; k <= n; k++){
			for(int l = 0; l <= n; l++){
				cout << dp[M][k][l] * get(a[i], n-k) % mod * fact[n] % mod << " ";
			}
			cout << endl;
		}*/
		
		llint sum = 0;
		for(int k = 0; k <= n; k++){
			for(int l = 1; l <= n; l++){
				sum += dp[M][k][l] * get(a[i], n-k) % mod, sum %= mod;
			}
		}
		sum *= fact[n], sum %= mod;
		sum *= modpow(modpow(c+1, n), mod-2), sum %= mod;
		//cout << sum << endl;
		ans += sum * b[i] % mod, ans %= mod;
	}
	cout << ans << endl;
	
	return 0;
}
0