2019 cattle and more passengers fifth school

2019 cattle and more passengers fifth school

A. digits2

solved at 00:47(+1)

Attendance problem, the \ (n \) output \ (n \) times can be, do not know what his teammates are thinking. . .

B. generator 1

upsolved

Fast power matrix, but the number is very high

Fast power just fine, actually thought out in decimal. . .

C. generator 2

upsolved

BSGS, need to change the size of the block so that the total complexity of lower

E. independent set 1

upsolved

There is a \ (n (1 <= n <= 26) \) FIG points, the maximum Q independently each subset graph and how much

\ (2 ^ n \) shaped pressure DP, provided \ (dp [i] \) represents the point state is \ (I \) a maximum independent set size, set \ (X \) is the \ (I \) the least significant bit \ (1 \) (so easy to transfer), then either do not contain the \ (1 \) , that is, \ (dp [I- (the X-<< 1)] \) , or contain the \ (1 \) , that is \ (. 1 + DP [I- (X <<. 1) - (I \ & G [X])] \) , where \ (G [x] \) represents \ (X \) form adjacent to the pressure set point , whichever maximum like, because the memory limit, \ (DP \) array need \ (char \) type

#include <bits/stdc++.h>
using namespace std;

char f[1 << 26];
int g[26], n, m, x, y, ans;

int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; ++i) {
        scanf("%d%d", &x, &y);
        g[x] |= 1 << y;
        g[y] |= 1 << x;
    }
    f[0] = 0;
    for(int i = 1; i < (1 << n); ++i) {
        int x = __builtin_ffs(i) - 1;
        f[i] = max((int)f[i ^ (1 << x)], 1 + f[(i ^ (1 << x)) - (i & g[x])]);
        ans += f[i];
    }
    printf("%d\n", ans);
    return 0;
}

F. maximum clique 1

upsolved

A \ (n (1 <= n <= 5000) \) th FIG, the weight of each bit point, two different two right point, two points to the right if and only if they point bin has at least two right different bits, seeking maximum output and a program group

Consider FIG its complement, the complement graph clearly edged by two points if and only if there is a bit different, is clearly a bipartite graph, to find the maximum independent set

G. subsequence 1

solved at 01:19

Two numeric string \ (S \) , \ (T \) , no longer than \ (3000 \) , seeking \ (S \) without leading \ (0 \) of the substring as a digital ratio \ (T \ ) a large number of programs

If a no leading \ (0 \) substring than \ (t \) long, it is certainly better than \ (t \) large number of combinations calculated

Consider next substring and \ (T \) as long set \ (dp [i] [j ] \) represents consideration \ (S \) before \ (I \) bits have chosen \ (J \) bit, and has more than \ (T \) before (J \) \ great, the number of programs, \ (DP2 is [I] [J] \) represents the equivalent program number, transfer equation can be easily pushed out (see Code), \ (DP [n-] [m] \) is the number of equal length scheme

#include <bits/stdc++.h>
using namespace std;

const int N = 3010, mod = 998244353;

int fac[N], invfac[N], ans, T, n, m;

int qp(int a, int n) {
    int res = 1;
    while(n) {
        if(n & 1)
            res = 1LL * res * a % mod;
        a = 1LL * a * a % mod;
        n >>= 1;
    }
    return res;
}

void init() {
    fac[0] = invfac[0] = 1;
    for(int i = 1; i < N; ++i) {
        fac[i] = 1LL * fac[i - 1] * i % mod;
        invfac[i] = qp(fac[i], mod - 2);
    }
}

int C(int n, int m) {
    return 1LL * fac[n] * invfac[n - m] % mod * invfac[m] % mod;
}


int dp[N][N], dp2[N][N];

char s[N], t[N];

int main() {
    init();
    scanf("%d", &T);
    while(T--) {
        scanf("%d%d%s%s", &n, &m, s + 1, t + 1);
        ans = 0;
        for(int i = 0; i <= n; ++i) {
            for(int j = 0; j <= m; ++j) dp[i][j] = dp2[i][j] = 0;
            dp2[i][0] = 1;
        }
        for(int i = 1; i <= n; ++i) {
            if(s[i] == '0') continue;
            for(int j = n - i; j >= m; --j) {
                ans = (ans + C(n - i, j)) % mod;
            }
        }
        //cout << ans << endl;
        for(int i = 1; i <= n; ++i) {
            for(int j = 1; j <= n; ++j) {
                dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % mod;;
                if(s[i] > t[j]) {
                    dp[i][j] = (dp[i][j] + dp2[i - 1][j - 1]) % mod;
                }
                dp2[i][j] = dp2[i - 1][j];
                if(s[i] == t[j])
                    dp2[i][j] = (dp2[i][j] + dp2[i - 1][j - 1]) % mod;
            }
        }
        ans = (ans + dp[n][m]) % mod;
        printf("%d\n", ans);
    }
    return 0;
}

H. subsequence 2

solved at 02:46

Length \ (n (1 <= n <= 10000) \) string, just before \ (m (2 <= m <= 10) \) lowercase letters and for which you \ (m * (m-1) / 2 \ ) string, represents the original string contains only two character sub-string, for example \ (ABC \) will give you \ (ab, bc, ac \ ) three substrings Please constructs a raw string

A glance in the past is a topological sorting, when the game wrote a segment tree optimization built in Fig. . . In fact, as long as the letters are built adjacent to the edge on the line

I. three points 1

upsolved

Teammates do give you the length of three sides of a rectangular area and a triangular inner rectangle, allows you to output the coordinates of the vertices of the triangle, one vertex to mate said longest side of the rectangle is provided at the apex, the apex on the other side of the rectangle on, look at the third point is legitimate enough

Guess you like

Origin www.cnblogs.com/tusikalanse/p/11291480.html