今天的模拟也太毒瘤了……

 

T1 permutation

  期望得分:20

  实际得分:20  

  我刚开始是这么想的:T1嘛,应该不会太难,想想正解吧。本来想求出所有不合法的情况,然后用n!减一下。于是用dp,但发现这玩意是有后效性的,硬推了将近一个点儿,最终还是放弃了。只能20分全排列暴力了……

  正解完全没看懂,居然成了什么二分图的补图,然后还用什么卷积……弃疗了

20分的

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<cstring>
 6 #include<cstdlib>
 7 #include<cctype>
 8 #include<vector>
 9 #include<stack>
10 #include<queue>
11 using namespace std;
12 #define enter puts("") 
13 #define space putchar(' ')
14 #define Mem(a, x) memset(a, x, sizeof(a))
15 #define rg register
16 typedef long long ll;
17 typedef double db;
18 const int INF = 0x3f3f3f3f;
19 const db eps = 1e-8;
20 const int maxn = 12;
21 const ll mod = 998244353;
22 inline ll read()
23 {
24     ll ans = 0;
25     char ch = getchar(), last = ' ';
26     while(!isdigit(ch)) {last = ch; ch = getchar();}
27     while(isdigit(ch)) {ans = ans * 10 + ch - '0'; ch = getchar();}
28     if(last == '-') ans = -ans;
29     return ans;
30 }
31 inline void write(ll x)
32 {
33     if(x < 0) x = -x, putchar('-');
34     if(x >= 10) write(x / 10);
35     putchar(x % 10 + '0');
36 }
37 
38 int n, k, a[maxn];
39 ll ans = 0;
40 
41 ll fac[maxn * 10000];
42 void work0()
43 {
44     fac[1] = 1;
45     for(int i = 2; i <= n; ++i) fac[i] = fac[i - 1] * i % mod;
46     write((fac[n] - fac[n - 1]) % mod); enter;
47 }
48 
49 int main()
50 {
51     freopen("permutation.in", "r", stdin);
52     freopen("permutation.out", "w", stdout);
53     n = read(); k = read();
54     if(n > 10) {work0(); return 0;}
55     for(rg int i = 1; i <= n; ++i) a[i] = i;
56     do
57     {
58         bool flg = 1;
59         for(rg int i = 1; i <= n; ++i) if(abs(a[i] - i) == k) {flg = 0; break;}
60         if(flg) ans++;
61     }while(next_permutation(a + 1, a + n + 1));
62     write(ans % mod); enter;
63     return 0;
64 }
View Code

相关文章: