UOJ273 [清華集訓2016] 你的生命已如風中殘燭 【數學】
阿新 • • 發佈:2018-07-21
數學 class mes ons 這樣的 生命 大於等於 bit return
題目分析:
把$0$卡牌看成$-1$。題目要求前綴和始終大於等於$1$。
最後添加一個$-1$,這樣除了最後一位之外大於等於1,最後一位等於0。
構造圓排列。這樣的話一個圓排列只有一個滿足的情況,然後考慮我們多出了一個$-1$,所以除去。
代碼:
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 const int maxn = 45; 5 const int mod = 998244353; 6 7 int n,m; 8 int a[maxn]; 9 10 void read(){ 11 scanf("%d",&n); 12 for(int i=1;i<=n;i++) scanf("%d",&a[i]),m += a[i]; 13 } 14 15 int ans = 1; 16 17 void work(){ 18 for(int i=1;i<=m;i++) if(i != m-n+1) ans = (1ll*ans*i)%mod; 19 printf("%d",ans); 20 } 21 22 int main(){ 23 read(); 24 work(); 25 return 0; 26 }
UOJ273 [清華集訓2016] 你的生命已如風中殘燭 【數學】