# Weekly 10 小结

A题

 1 T = int(input())
2 while T:
3     T -= 1
4     s = raw_input()
5     n = len(s)
6     res, pre = 0, 0
7     for i in xrange(1, n):
8         if (s[i] == s[pre]):
9             res += 1
10         else:
11             pre = i
12     print res

B题

 1 n, k = map(int, raw_input().split())
2 s = raw_input()
3
4 res = []
5 ans = 0
6 for i in xrange(n):
7     if i >= k:
8         ans ^= int(res[i-k])
9     tmp = ans ^ int(s[i])
10     res.append(tmp)
11     ans ^= tmp
12 print ''.join(map(str, res))

C题

 1 #include <cmath>
2 #include <cstdio>
3 #include <vector>
4 #include <cstring>
5 #include <iostream>
6 #include <algorithm>
7 using namespace std;
8
9 typedef long long LL;
10 const int MOD = 1e9 + 7;
11 #define rep(i, n) for (int i = (1); i <= (n); i++)
12 LL N, K, A[20], f[20];
13 struct Matrix {
14     LL a[20][20];
15     Matrix() {memset(a, 0, sizeof(a));}
16
17     Matrix operator * (const Matrix &x) const {
18         Matrix c;
19         rep (i, 15) rep (k, 15) rep (j, 15) c.a[i][j] = (c.a[i][j] + x.a[k][j] * a[i][k]) % MOD;
20         return c;
21     }
22 };
23
24 Matrix pow_mod(Matrix a, LL b) {
25     if (b < 0) return a;
26     Matrix res;
27     rep (i, K) res.a[i][i] = 1;
28     while (b > 0) {
29         if (b & 1) res = res * a;
30         a = a * a;
31         b >>= 1;
32     }
33     return res;
34 }
35
36
37 int main() {
38     ios::sync_with_stdio(false);
39     cin >> N >> K;
40     rep (i, K) cin >> A[i];
41
42     sort(A + 1, A + K + 1);
43     f[0] = 1;
44     rep (i, 15) rep (j, K) if (i >= A[j]) f[i] = (f[i] + f[i - A[j]]) % MOD;
45     rep (i, 15) cerr << f[i] << endl;
46     if (N <= 15) {
47         cout << f[N] * 2 % MOD << endl;
48         return 0;
49     }
50
51     Matrix a; rep (i, 15) a.a[i][i-1] = 1;
52     a.a[1][1] = 0; rep (i, K) a.a[1][A[i]] = 1;
53     Matrix res = pow_mod(a, N - 15);
54     LL ans = 0;
55     rep (i, 15) ans = (ans + res.a[1][i] * f[16 - i]) % MOD;
56     ans = (ans * 2) % MOD;
57     cout << ans << endl;
58     return 0;
59 }

D题

 1 #include <cmath>
2 #include <cstdio>
3 #include <vector>
4 #include <iostream>
5 #include <algorithm>
6 using namespace std;
7
8 #define rep(i, n) for (int i = (1); i <= (n); i++)
9 typedef long long LL;
10 const int MAX_N = 500050;
11 const LL INF = (LL)1e18;
12 int V[MAX_N], P[MAX_N];
13 LL tree[MAX_N];
14 int N;
15
16 int main() {
17     scanf("%d", &N);
18     for (int i = 1; i <= N; i++) scanf("%d %d", V+i, P+i);
19
20     fill(tree+1, tree+N+1, -INF);
21     LL ans = tree[N] = V[N], sum = 0;
22     for (int i = N-1; i >= 1; i--) {
23         ans = -INF;
24         for (int x = min(i+P[i], N); x > 0; x -= x&-x)
25             ans = max(ans, tree[x]);
26         if (ans > -INF) {
27             for (int x = i; x <= N; x += x&-x)
28                 tree[x] = max(tree[x], ans - V[i]);
29         }
30
31         ans += sum;
32         sum += V[i];
33     }
34     printf("%lld\n", ans);
35
36     return 0;
37 }

E题