Codeforces Round #302 (Div. 2)
A. Set of Strings
The string q is called "beautiful" when and only if Q can be split into K-strings (S1, S2, S3, ..., SK) and any two strings satisfy the first letter.
Direct simulation, the Q of each character to judge, if the character has not appeared before, then it can be formed from the beginning of a new string, and the count, if it is K, then the following will be grouped into a string.
#include <cstring>#include<iostream>using namespacestd;Charans[ -][ -];intMain () {intN; strings; CIN>> N >>s; int_n =N; intvis[ -] = {0}; intK =0; for(intI=0; I<s.size (); i++) { if(Vis[s[i]-'a'] ==0) {ans[n][k++] =' /'; N--; Vis[s[i]-'a'] =1; K=0; } ans[n][k++] =S[i]; if(n = =0) { intJ; for(j=i+1; J<s.size (); J + +) {ans[n][k++] =S[j]; } ans[n][k++] =' /'; Break; } } if(n = =0) {cout<<"YES"<<Endl; for(inti=_n-1; i>=0; i--) {cout<< Ans[i] <<Endl; } } Else{cout<<"NO"<<Endl; } return 0;}View Code
B. Sea and Islands
Ask if there can be a K island in a n*n sea. The island is defined as all the points on the island are connected together, and the point is connected in only four directions.
To arrange as many islands as possible, you have to make each small island the smallest, so just a little bit better. The problem becomes that the K-squares are arranged in the square of the n*n, and they do not lead. (The test instructions of this question is very difficult to understand)
#include <iostream>using namespacestd;Chars[101][101];intMain () {intN; intK; CIN>> N >>K; for(intI=0; i<n; i++) { for(intj=0; j<n; J + +) {S[i][j]='S'; } } intCNT =0; for(intI=0; i<n; i++) { for(intj=0; j<n; J + +) { if(cnt = = k)Continue; if(i%2= = j%2) {S[i][j]='L'; CNT++; } } } if(CNT = =k) {cout<<"YES"<<Endl; for(intI=0; i<n; i++) { for(intj=0; j<n; J + +) {cout<<S[i][j]; } cout<<Endl; } } Else{cout<<"NO"<<Endl; } return 0;}View Code
C. Writing Code
Arrange for n person to write m line code, each person every line out a[i] A bug, the maximum number of scenarios for a B bug.
A two-dimensional full backpack, everyone has two states: Write J line code out K bug
DP[I][J][K] First I programmers write Money J line the number of programs that appear K bugs.
DP[I][J][K] = Dp[i][j-1][k-a[i]] + dp[i-1][j][k];
Note that the array here is hyper-memory and requires a scrolling array.
#include <iostream>using namespacestd;intN, M, b;Long LongMoD;Long Longa[505];Long Longdp[2][505][505];intMain () {CIN>> n >> m >> b >>MoD; for(intI=1; i<=n; i++) {cin>>A[i]; } for(intI=1; i<=n; i++) Dp[i%2][0][0] =1L; for(intI=1; i<=n; i++) { for(intj=1; j<=m; J + +) { for(intk=0; k<=b; k++) { if(K < a[i]) Dp[i%2][j][k] = dp[(i-1) %2][J][K]%MoD; ElseDp[i%2][j][k] = (dp[i%2][j-1][k-a[i]] + dp[(i-1) %2][J][K])%MoD; } } } Long LongAns =0; for(intI=0; i<=b; i++) {ans= (ans + dp[n%2][m][i])%MoD; } cout<< ans% mod <<Endl; return 0;}View Code
Codeforces Round #302 (Div. 2) A B C