聯賽模擬測試19

A.建設城市

考場暴搜+特判\(20pts\)
正解是子集反演但是我不能理解
還是容斥比較好理解
利用隔板法得到隨意選擇的方案數量爲\(C_{m-1}^{n-1}\)
答案是隨便選-至少一個不滿足的+至少兩個不滿足的-至少三個不滿足的……
至少\(i\)個不滿足的方案數爲\(C_n^i * C_{m-i*k-1} ^ {n-1}\)
\(n>m\)顯然無解是\(0\),所以說數據相當於就是\(1e7\)
然後直接出代碼

City
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

inline int read(){
	int x = 0, w = 1;
	char ch = getchar();
	for(; ch > '9' || ch < '0'; ch = getchar()) if(ch == '-') w = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	return x * w;
}

inline void write(register int x){
	if(x < 0) x = ~x + 1, putchar('-');
	if(x > 9) write(x / 10);
	putchar(x % 10 + '0');
}

const int mod = 998244353;

int n, m, k, minn;
int ans;
inline void dfs(register int cnt, register int tmp){//放好了cnt個城市,tmp隊伍剩餘數量
	if(cnt == n){
		if(tmp == 0) ans++;
		return;
	}
	for(register int i = 1; i <= k; i++)
		dfs(cnt + 1, tmp - i);
}

signed main(){
	freopen("1.in", "r", stdin);
	freopen("1.out", "w", stdout);
	n = read(), m = read(), k = read();
	if(n > m) return puts("0"), 0;
	minn = min(m, k);
	dfs(0, m);
	printf("%d\n", ans);
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章