Tucao: It will be mixed in Div 2 for a lifetime.
A, B, and C are simple questions. You can see the number of AC users.
A: If we define an array as N * n, we don't need to consider the boundary.
1 #include<iostream> 2 #include <string> 3 #include <vector> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 #include<string> 8 #include<algorithm> 9 using namespace std;10 #define inf 0x3f3f3f11 #define N 1234512 typedef long long ll;13 int a[N];14 char s[123][123];15 int main()16 {17 int n;18 scanf("%d",&n);19 for (int i=1;i<=n;i++)20 scanf("%s",s[i]+1);21 22 int flag=1;23 for (int i=1;i<=n;i++)24 for (int j=1;j<=n;j++){25 int ans=0;26 if (s[i-1][j]==‘o‘) ans++;27 if (s[i][j-1]==‘o‘) ans++;28 if (s[i][j+1]==‘o‘) ans++;29 if (s[i+1][j]==‘o‘) ans++;30 if (ans&1) {flag=0;break;}31 }32 33 if (flag) printf("YES");34 else printf("NO");35 return 0;36 }
B: The language is actually .....
It can be greedy...
Sort 26 letters
233
1 #include<iostream> 2 #include <string> 3 #include <vector> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 #include<string> 8 #include<algorithm> 9 using namespace std;10 #define inf 0x3f3f3f11 #define N 12345612 typedef long long ll;13 ll a[N];14 string s;15 int main()16 {17 int n;18 ll k;19 cin>>n>>k;20 cin>>s;21 for (int i=0;i<s.size();i++)22 a[s[i]-‘A‘]++;23 sort(a,a+26);24 ll ans=0;25 for (int i=26;i>=0;i--)26 {27 if (k>=a[i]) {ans+=a[i]*a[i];k-=a[i];28 }29 else {ans+=k*k;break;}30 }31 cout<<ans<<endl;32 return 0;33 }
This is also a greedy practice ..
Because we need to add a certain number of numbers...
If the sorting is good, increase as much as possible .. So every time we kick the smallest one out.
You can calculate the value of each number.
1 #include<iostream> 2 #include <string> 3 #include <vector> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 #include<string> 8 #include<algorithm> 9 using namespace std;10 #define inf 0x3f3f3f11 #define N 32345612 typedef long long ll;13 ll a[N];14 string s;15 int main()16 {17 int n;18 cin>>n;19 for (int i=1;i<=n;i++)cin>>a[i];20 ll ans=0;21 sort(a+1,a+n+1);22 for (int i=1;i<n;i++)23 ans+=a[i]*(i+1);24 ans+=a[n]*n;25 cout<<ans;26 return 0;27 }
D: I have practiced a lot of tree-like DP, but I have no idea about this question. It's a waste of life Div 2.
Idea: Define DP [I] [1] to indicate that there are black nodes in the number where I is the root.
DP [I] [0] indicates that no black node exists ..
Transfer Equation
U is the root subnode.
Initial: DP [root] [color [root] = 1;
DP [root] [1] = DP [root] [1] * DP [u] [1] + dp [root] [0] * DP [u] [1] + DP [root] [1] * DP [u] [0];
DP [root] [0] = DP [root] [0] * DP [u] [0] + dp [root] [0] * DP [u] [1];
1 #include<iostream> 2 #include <string> 3 #include <vector> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 #include<algorithm> 8 #define N 112345 9 #define inf 100000000710 typedef long long ll;11 using namespace std;12 vector<int>G[N];13 ll dp[N][2];14 int col[N];15 int n;16 17 18 void dfs(int root,int pre)19 {20 dp[root][col[root]]=1;21 for (int i=0;i<G[root].size();i++)22 {23 int x=G[root][i];24 if (x==pre) continue;25 dfs(x,root);26 dp[root][1]=(dp[root][1]*dp[x][0]%inf+dp[root][1]*dp[x][1]+dp[root][0]*dp[x][1])%inf;27 dp[root][0]=(dp[root][0]*dp[x][1]%inf+dp[root][0]*dp[x][0]%inf)%inf;28 }29 }30 31 int main()32 {33 scanf("%d",&n);34 for (int i=1;i<n;i++)35 {36 int x;37 scanf("%d",&x);38 G[i].push_back(x);39 G[x].push_back(i);40 }41 for (int i=0;i<n;i++)42 scanf("%d",&col[i]);43 dfs(0,-1);44 printf("%d\n",dp[0][1]);45 return 0;46 }
Postscript:
Tree DP is abstract... More questions can be done to improve
Codeforces round #263 (Div. 2)