T1 SB题
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define inf (0x7fffffff)10 #define l(a) ((a)<<1)11 #define r(a) ((a)<<1|1)12 #define b(a) (1<<(a))13 #define rep(i,a,b) for(int i=a;i<=(b);i++)14 #define clr(a) memset(a,0,sizeof(a))15 typedef long long ll;16 typedef unsigned long long ull;17 using namespace std;18 ll a,b,c;19 ll gcd(ll x,ll y){20 return y?gcd(y,x%y):x;21 }22 int main(){23 scanf("%lld%lld%lld",&a,&b,&c);24 ll t=a/gcd(a,b)*b;25 cout<
T2 Sort贪心 注意边界和特殊情况
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define inf (0x7fffffff)10 #define l(a) ((a)<<1)11 #define r(a) ((a)<<1|1)12 #define b(a) (1<<(a))13 #define rep(i,a,b) for(int i=a;i<=(b);i++)14 #define clr(a) memset(a,0,sizeof(a))15 typedef long long ll;16 typedef unsigned long long ull;17 using namespace std;18 const int maxn=200009;19 ll n,S,L,sum[maxn],H[maxn];20 struct tree{21 ll h,a,m;22 inline bool operator<(const tree T)const{23 return m =S){40 flag=1;41 if(i==1) cout< <=H[1]?0:(S-H[1])/t[1].a+ll((S-H[1])%t[1].a!=0))<
T3 DP 我tm把m打成n 一直wa
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define inf (0x3f3f3f3f)10 #define l(a) ((a)<<1)11 #define r(a) ((a)<<1|1)12 #define b(a) (1<<(a))13 #define rep(i,a,b) for(int i=a;i<=(b);i++)14 #define clr(a) memset(a,0,sizeof(a))15 typedef long long ll;16 typedef unsigned long long ull;17 using namespace std;18 int readint(){19 int t=0,f=1;char c=getchar();20 while(!isdigit(c)){21 if(c=='-') f=-1;22 c=getchar();23 }24 while(isdigit(c)){25 t=(t<<3)+(t<<1)+c-'0';26 c=getchar();27 }28 return t*f;29 }30 const int maxn=6009;31 int n,m,_A,_B,a[maxn],b[maxn],c[5][5],d[maxn][maxn][3];32 char A[maxn],B[maxn];33 int f(char c){34 if(c=='A') return 1;35 if(c=='T') return 2;36 if(c=='G') return 3;37 return 4;38 }39 int main(){40 scanf("%s%s",A,B);n=strlen(A);m=strlen(B);41 rep(i,1,n) a[i]=f(A[i-1]);42 rep(i,1,m) b[i]=f(B[i-1]);43 rep(i,1,4)44 rep(j,1,4) c[i][j]=readint();45 _A=readint();_B=readint();_A=-_A;_B=-_B;46 rep(i,0,n)47 rep(j,0,m) 48 rep(k,0,2) d[i][j][k]=-inf;49 d[0][0][0]=0;50 rep(i,0,n){51 rep(j,0,m){52 rep(k,0,2) if(i>0&&j>0) d[i][j][0]=max(d[i][j][0],d[i-1][j-1][k]+c[a[i]][b[j]]);53 if(j){54 d[i][j][1]=max(d[i][j][1],d[i][j-1][0]+_A);55 d[i][j][1]=max(d[i][j][1],d[i][j-1][1]+_B);56 d[i][j][1]=max(d[i][j][1],d[i][j-1][2]+_A);57 }58 if(i){59 d[i][j][2]=max(d[i][j][2],d[i-1][j][0]+_A);60 d[i][j][2]=max(d[i][j][2],d[i-1][j][2]+_B);61 d[i][j][2]=max(d[i][j][2],d[i-1][j][1]+_A);62 }63 }64 }65 int ans=-inf;66 rep(i,0,2) ans=max(ans,d[n][m][i]);67 printf("%d\n",ans);68 return 0;69 }
T4 并不难的DP...
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define inf (0xffffffffll)10 #define l(a) ((a)<<1)11 #define r(a) ((a)<<1|1)12 #define b(a) (1<<(a))13 #define rep(i,a,b) for(int i=a;i<=(b);i++)14 #define clr(a) memset(a,0,sizeof(a))15 typedef long long ll;16 typedef unsigned long long ull;17 using namespace std;18 ll readll(){19 ll t=0,f=1;char c=getchar();20 while(!isdigit(c)){21 if(c=='-') f=-1;22 c=getchar();23 }24 while(isdigit(c)){25 t=(t<<3ll)+(t<<1ll)+ll(c-'0');26 c=getchar();27 }28 return ll(t*f);29 }30 const int maxm=1000009;31 ll n,m,d[maxm],a[maxm],q[maxm];32 struct node{33 ll p,w;34 inline bool operator<(const node A)const{35 return p >j);t2=s2[j]+((a[i-cnt]&(1< >j);75 if(t1>t2){76 d[i]+=t2*(1ll< <