The Junior goal is to yellow codeforces!
Start with div1 and do the first three questions each time.
A
A simple DP.
#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cstdlib>#include<string>#include<cmath>#include<vector>#define LL long long#define MAXN 100005using namespace std;LL vis[100005];LL dp[1000005];int main(){ int n; scanf("%d",&n); int maxi=0; for(int i=0; i<n; ++i) { int a; scanf("%d",&a); vis[a]+=a; maxi=max(maxi,a); } for(int i=1; i<=maxi; ++i) if(i-2>=0) dp[i]=max(dp[i-1],dp[i-2]+vis[i]); else dp[i]=vis[i]; printf("%I64d\n",dp[maxi]); return 0;}
View code
B
Tire + dp + game
Win [I] indicates whether there is a possibility of victory in the first hand at the I node, and lost [I] indicates whether there is a possibility of failure in the first hand at the current I node.
In this way, you can determine whether the first hand has the possibility of winning or failing, and then perform a simple game.
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<vector>using namespace std;int n,K;struct Tire{ int ch[100005][26]; bool win[100005],lost[100005]; int sz; int newnode() { memset(ch[sz],0,sizeof(ch[sz])); win[sz]=lost[sz]=0; return sz++; } void init() { sz=0; newnode(); } int getX(char c) { return c-‘a‘; } void insert(char *word) { int now=0; for(int i=0; word[i]; ++i) { int x=getX(word[i]); if(ch[now][x]==0) ch[now][x]=newnode(); now=ch[now][x]; } } bool getWin(int now) { win[now]=false; bool noChild=true; for(int i=0; i<26; ++i) { if(ch[now][i]) { noChild=false; win[now]|=(!getWin(ch[now][i])); } } if(noChild) return win[now]=false; return win[now]; } bool getLost(int now) { lost[now]=false; bool noChild=true; for(int i=0; i<26; ++i) { if(ch[now][i]) { noChild=false; lost[now]|=(!getLost(ch[now][i])); } } if(noChild) return lost[now]=true; return lost[now]; }};char word[100005];Tire tree;int main(){ scanf("%d%d",&n,&K); tree.init(); for(int i=1; i<=n; ++i) { scanf("%s",word); tree.insert(word); } bool firstWin=false,firstLost=false; firstWin=tree.getWin(0); firstLost=tree.getLost(0); if(!firstWin) puts("Second"); else { if(firstLost) puts("First"); else { if(K&1) puts("First"); else puts("Second"); } } return 0;}
View code
Codeforces round #260 (Div. 1)