2016-2017 ACM-ICPC Southeastern European Regional programming Contest (SEERC 2016)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.