A-concerts
Thought: Dp[i][j] said I saw the J-concert in the first day. Transfer equation: dp[i][j]=dp[i-1][j]+dp[The last date][j-1] determined by the H array.
#include<bits/stdc++.h>using namespace std;int h[300];char plan[305],schedule[100005];int k,n;int dp[100005][305];const int mod=1e9+7;int main(){ while(~scanf("%d%d",&k,&n)) { for(int i=‘A‘;i<=‘Z‘;++i)scanf("%d",h+i); scanf("%s%s",plan,schedule); dp[1][1]=(plan[0]==schedule[0]);for(int i=2;i<=n;++i)dp[i][1]=(plan[0]==schedule[i-1])?dp[i-1][1]+1:dp[i-1][1]; for(int i=2;i<=k;++i)dp[1][i]=0; for(int j=2;j<=k;++j) { for(int i=2;i<=n;++i) { dp[i][j]=dp[i-1][j]; if(plan[j-1]==schedule[i-1]&&i-h[plan[j-2]]>=2)dp[i][j]=(1LL*dp[i][j]+dp[i-1-h[plan[j-2]]][j-1])%mod; } } printf("%d\n",dp[n][k]); }}
D-harry Potter and the Vector Spell
Ideas: And check set
#include<bits/stdc++.h>using namespace std;const int maxn=1e5+5;vector<int> a[maxn];int n,m;int fa[maxn];int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}int main(){ while(~scanf("%d%d",&m,&n)) { for(int i=1;i<=m;++i) { fa[i]=i; int k,tmp;scanf("%d",&k); for(int j=1;j<=k;++j) { scanf("%d",&tmp); a[tmp].push_back(i); } } int ans=0; for(int i=1;i<=n;++i) { int u=a[i][0],v=a[i][1]; int x=find(u),y=find(v); if(x!=y){ans++;fa[x]=y;} } printf("%d\n",ans); }}
G-robots
Water problem
K-escape
Water problem
2016-2017 ACM-ICPC Southeastern European Regional programming Contest (SEERC 2016)