ACM multi-season training school Luo Guchun fifth week

T127120 Change

Bipartite graph matching;

Recall bipartite graph matching algorithm, a point is matched if and only if (! Match [v] || findpath (match [v])), but must use a vis to record when you record,

Otherwise, the card will at some point get out. And each must find augmenting paths cleared vis.

note:

1. Define a vis, or a point of looking into augmenting path can not get out,

2. Each traverse emptying vis, otherwise the answer must be wrong.

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=300+5;
vector<int>e[N];
int match[N];
int n;
bool vis[N];
bool findpath(int u){
    for(int i=0;i<e[u].size();i++){
    int v=e[u][i];
    if(!vis[v]){
    VIS [V] = . 1 ;
     IF (! match [V] || FindPath (match [V])) { // can match to match another match otherwise 
    match [V] = U;
     return  . 1 ;
    }
    }
    }
    return 0;
}   
char s[150];
int main(){
    memset(vis,0,sizeof vis);
    memset(match,0,sizeof match);
    int k;scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&k);
        char tmp[30]={0};
        for(int j=1;j<=k;j++){
            scanf("%s",s);
            int x=s[0]-'a'+101;
            if(s[0]-'a'+1>n)continue;
            if(!tmp[s[0]-'a'])e[i].pb(x);
            tmp[s[0]-'a']=1;        
    }
    }
    bool flag=1;
    for(int j=1;j<=n;j++){
        memset(vis,0,sizeof vis);
        findpath(j);
    }
    for(int i=1;i<=n;i++)if(!match[i+100])flag=0;
    if(flag)puts("Yes");
    else puts("No");
    // system("pause");
    return 0;
}
View Code

T127124 Flaw

Press the meaning of the questions can be simulated.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int N=300+5;
int main(){
    // cout<<<<endl;    
    // ll a=pow(2,31);
    // cout<<a<<endl;    
    ll n1,n2;
    ll M=pow(2,31);
    char op;
    scanf("a+%lld%c%lld",&n1,&op,&n2);
    if(op=='>')printf("%lld\n",M-n2-1);
    else printf("lld\n",M+n2);

    // system("pause");
    return 0;
}
View Code

T127125 Gene

Ordinary dp

#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=(int)j;i<=(int)k;i++)
#define per(i,j,k) for(int i=(int)k;i>=(int)j;i--)
#define pb push_back
#define pf push_front
#define fi first
#define se second 11
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
typedef double db;
const db PI=acos(-1.0);
const ll INF=0x3f3f3f3f3f3f3f3fLL;
const int inf=0x3f3f3f3f;//0x7fffffff;
const double eps=1e-9;
const ll MOD=1e9+7;
const int N=5e3+5;
ll dp[N][N];
int main () {
    ll n,m,a,b,c;
    scanf("%lld %lld %lld %lld %lld",&n,&m,&a,&b,&c);
    string s1,s2;
    cin>>s1>>s2;
    for(int i=0;i<=n;i++)dp[i][0]=-i*c;
    for(int i=0;i<=m;i++)dp[0][i]=-i*c;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
        if(s1[i-1]==s2[j-1])
        dp[i][j]=dp[i-1][j-1]+a;
        else dp[i][j]=max(max(dp[i-1][j],dp[i][j-1])-c,dp[i-1][j-1]-b);

        }
    }
    printf("%lld\n",dp[n][m]);
    // system("pause");
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/littlerita/p/12590273.html