2018 TCO Algorithm Round 1B

250 LineOff

随便搞

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 class LineOff {
 5 public:
 6     int movesToDo(string points) {
 7         stack<char> st;
 8         int ret = 0, l = points.length();
 9         for(int i = 0; i < l; ++i){
10             if(!st.empty() && st.top() == points[i]) ret++, st.pop();
11             else st.push(points[i]);
12         }
13         return ret;
14     }
15 };
Aguin

 

600 StablePairsDiv1

随便搞

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef pair<int, int> pii;
 4 int f[111][111][111];
 5 pii pre[111][111][111];
 6 
 7 class StablePairsDiv1 {
 8 public:
 9     void get(int step, int i, int j, vector<int> & ret){
10         if(step != 1) get(step - 1, pre[step][i][j].first, pre[step][i][j].second, ret);
11         ret.push_back(i);
12         ret.push_back(j);
13     }
14     vector<int> findMaxStablePairs(int n, int c, int k) {
15         memset(f, -1, sizeof(f));
16         for(int i = 1; i <= n; ++i)
17             for(int j = i + 1; j <= n; ++j)
18                 f[1][i][j] = i + j;
19         for(int i = 1; i < k; ++i){
20             for(int j = 1; j <= n; ++j){
21                 for(int k = j + 1; k <= n; ++k){
22                     if(f[i][j][k] == -1) continue;
23                     for(int p = k + 1; p <= n; ++p){
24                         int q = j + k + c - p;
25                         if(q <= p) break;
26                         int t = f[i][j][k] + p + q;
27                         if(t > f[i+1][p][q]) f[i+1][p][q] = t, pre[i+1][p][q] = pii(j, k);
28                     }
29                 }
30             }
31         }
32         int ans = -1, ii, jj;
33         for(int i = 1; i <= n; ++i){
34             for(int j = i + 1; j <= n; ++j){
35                 if(f[k][i][j] > ans) ans = f[k][i][j], ii = i, jj = j;
36             }
37         }
38         vector<int> ret;
39         if(ans == -1) return ret;
40         get(k, ii, jj, ret);
41         return ret;
42     }
43 };
Aguin

 

1000 ThreeSameLetters

随便搞

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const LL mod = 1e9 + 7;
 5 
 6 LL f[66][66][4][2];
 7 class ThreeSameLetters {
 8 public:
 9     int countStrings(int L, int S){
10         for(int i = 1; i <= S; ++i) f[1][i][1][0] = 1;
11         for(int i = 1; i < L; ++i){
12             for(int j = 1; j <= S; ++j){
13                 for(int k = 1; k <= 3; ++k){
14                     for(int p = 0; p <= 1; ++p){
15                         for(int q = 1; q <= S; ++q){
16                             int nk = q == j ? k + 1 : 1;
17                             if(nk > 3) continue;
18                             if(p && nk == 3) continue;
19                             int np = p || nk == 3;
20                             f[i+1][q][nk][np] = (f[i+1][q][nk][np] + f[i][j][k][p]) % mod;
21                         }
22                     }
23                 }
24             }
25         }
26         LL ans = 0;
27         for(int i = 1; i <= S; ++i) ans = (ans + f[L][i][1][1] + f[L][i][2][1] + f[L][i][3][1]) % mod;
28         return (int) ans;
29     }
30 };
Aguin

 

posted @ 2018-05-05 11:33  Aguin  阅读(396)  评论(0编辑  收藏  举报