Tag: getch, But I'm ATI ext Clu pre direct perm OSI
A very rewarding question (? ° ?)??
The limit is m, which seems to be not well handled. In general, what I know is exactly the K condition. Instead of using the combination number/dp state transfer/slope to divide the two points, there will be only room for rejection. We can first process the num [I], indicating that there are at least I perfect number of solutions, and then we can get the ANS [m] (exactly m ). How to obtain the num array? Set the DP status to f [I] [J] [p] [Q], where p and q are 01, indicating that DP is at the I position, there are already J perfect locations, and whether I and I + 1 have been used. Analysis of transfer cases: 1. the current position is not a perfect position. Ignore it directly. 2. fill in I-1 as a perfect position; 3. enter I + 1 as the perfect position. Then, simply multiply the number that is ignored in the upper order.
This status is not very good to think about, but we mainly need to make it clear that the I position is perfect, only related to I-1 and I + 1, only I + 1 has an impact on the next position. We can skip the ignored number directly. Because I is not used currently, I cannot influence the formation of perfect number. As for content rejection, I will still only roll back the \ (N ^ {2} \) from at least to exactly ...... The full back-to-back sub-formula of O (n :(
\ (ANS [m] = num [m]-C (m + 1, m) * num [M + 1]... * (-1) ^ {n-m} * C (n, m) * num [N] \)
#include <bits/stdc++.h>using namespace std;#define maxn 1500 #define int long long#define mod 1000000007int n, K, f[maxn][maxn][2][2], num[maxn];int ans[maxn], fac[maxn], C[maxn][maxn];int read(){ int x = 0, k = 1; char c; c = getchar(); while(c < ‘0‘ || c > ‘9‘) { if(c == ‘-‘) k = -1; c = getchar(); } while(c >= ‘0‘ && c <= ‘9‘) x = x * 10 + c - ‘0‘, c = getchar(); return x * k;}void Up(int &x, int y) { x = (x + y) % mod; }void pre(){ fac[0] = 1; for(int i = 1; i < maxn; i ++) fac[i] = fac[i - 1] * i % mod; for(int i = 0; i < maxn; i ++) C[i][0] = 1; for(int i = 1; i < maxn; i ++) for(int j = 1; j < maxn; j ++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod; }signed main(){ pre(); n = read(), K = read(); f[0][0][1][0] = 1; for(int i = 0; i < n; i ++) { for(int j = 0; j <= i; j ++) for(int p = 0; p <= 1; p ++) for(int q = 0; q <= 1; q ++) { Up(f[i + 1][j][q][0], f[i][j][p][q]); if(!p) Up(f[i + 1][j + 1][q][0], f[i][j][p][q]); if(i < n - 1) Up(f[i + 1][j + 1][q][1], f[i][j][p][q]); } } for(int i = 0; i <= n; i ++) { for(int p = 0; p <= 1; p ++) for(int q = 0; q <= 1; q ++) Up(num[i], f[n][i][p][q]); num[i] = num[i] * fac[n - i] % mod; } ans[K] = num[K]; for(int i = K + 1, t = -1; i <= n; i ++, t *= -1) Up(ans[K], (t * C[i][K] * num[i] % mod) + mod); /*for(int i = n; i >= K; i --) { int t = num[i]; for(int j = n; j > i; j --) t = (t - (ans[j] * C[j][i]) % mod + mod) % mod; ans[i] = t; }*/ printf("%lld\n", ans[K]); return 0;}
[Problem] CF #175 (Div. 2) E-positions in Permutations