T127120 Change
二分图匹配;
回忆一下二分图匹配算法,一个点被匹配当且仅当 (!match[v]||findpath(match[v])) ,但你记录时一定要用一个vis来记录,
不然一定会卡在某一个点出不来。而且每次找增广路都必须清空vis。
注意:
1.定义一个vis,否则陷入一个点找增广路出不来,
2.每次遍历清空vis,否则答案必定不对。
#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])){//能匹配就匹配 不然换个匹配 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
按题意模拟即可。#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
普通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