zoukankan      html  css  js  c++  java
  • COCI ACM 用生命在dp直接裂开阿巴阿巴阿巴

    Description

    Sample Input

    3
    1 3 3
    1 1 1
    1 2 3

    Sample Output

    4
    用生命在dp啊啊啊
    考虑dp[i][j][k] i表示当前选择了i个数 j表示以j列结尾 k为二进制表示当前有那些行在里面比如001表示第一行010表示第二行100表示第三行110表示第二行和第三行
    阿巴阿巴阿巴我直接裂开(状态转移方程有点复杂阿巴阿巴阿巴
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cctype>
    #include<cmath>
    #include<set>
    #include<vector>
    #include<map>
    #include<queue>
    #include<iostream>
    #define ll long long
    using namespace std;
    namespace FAST_IO {
        #define IN_LEN 250000
        #define OUT_LEN 250000
        inline char Getchar() {
            static char buf[IN_LEN], *l=buf,*r=buf;
            if (l==r) r=(l=buf)+fread(buf,1,IN_LEN,stdin);
            return (l==r)?EOF:*l++;
        }
        char obuf[OUT_LEN], *ooh = obuf;
        inline void Putchar(char c) {
            if (ooh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout),ooh = obuf;
            *ooh++ = c;
        }
        inline ll rd(){
            ll x=0;int ch=Getchar(); bool f=1;
            while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=Getchar();
            if (ch=='-'){f=0;ch=Getchar();}
            while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=Getchar();}
            return f?x:-x;
        }
        void write(ll x){ if (x>=10) write(x/10),Putchar((char)(x%10+'0')); else Putchar((char)(x+'0')); }
        inline void flush() { fwrite(obuf, 1, ooh - obuf, stdout); }
    }//快读 可以节省400ms(u1s1可能我们oj的评测机慢了点
    const int INF=1e9;
    int n,a[150010],b[150010],c[150010],dp[150010][3][8];
    int min(int a,int b,int c){return min(a,min(b,c));}
    using namespace FAST_IO;
    
    void add0(int t){
    	dp[t][0][1]=dp[t-1][0][1]+a[t];
    	dp[t][0][3]=min(dp[t-1][0][3]==0?INF:dp[t-1][0][3]+a[t],dp[t-1][1][2]+a[t]);
    	dp[t][0][5]=min(dp[t-1][0][5]==0?INF:dp[t-1][0][5]+a[t],dp[t-1][2][4]+a[t]);
    	dp[t][0][7]=min(dp[t-1][0][7]==0?INF:dp[t-1][0][7]+a[t],dp[t-1][1][6]==0?INF:dp[t-1][1][6]+a[t],dp[t-1][2][6]==0?INF:dp[t-1][2][6]+a[t]);
    }
    
    void add1(int t){
    	dp[t][1][2]=dp[t-1][1][2]+b[t];
    	dp[t][1][3]=min(dp[t-1][1][3]==0?INF:dp[t-1][1][3]+b[t],dp[t-1][0][1]+b[t]);
    	dp[t][1][6]=min(dp[t-1][1][6]==0?INF:dp[t-1][1][6]+b[t],dp[t-1][2][4]+b[t]);
    	dp[t][1][7]=min(dp[t-1][1][7]==0?INF:dp[t-1][1][7]+b[t],dp[t-1][0][5]==0?INF:dp[t-1][0][5]+b[t],dp[t-1][2][5]==0?INF:dp[t-1][2][5]+b[t]);
    }
    
    void add2(int t){
    	dp[t][2][4]=dp[t-1][2][4]+c[t];
    	dp[t][2][5]=min(dp[t-1][2][5]==0?INF:dp[t-1][2][5]+c[t],dp[t-1][0][1]+c[t]);
    	dp[t][2][6]=min(dp[t-1][2][6]==0?INF:dp[t-1][2][6]+c[t],dp[t-1][1][2]+c[t]);
    	dp[t][2][7]=min(dp[t-1][2][7]==0?INF:dp[t-1][2][7]+c[t],dp[t-1][0][3]==0?INF:dp[t-1][0][3]+c[t],dp[t-1][1][3]==0?INF:dp[t-1][1][3]+c[t]);
    }
    int main(){
    	n=rd();
    	for(int i=1;i<=n;i++)a[i]=rd();
    	for(int i=1;i<=n;i++)b[i]=rd();
    	for(int i=1;i<=n;i++)c[i]=rd();
    	dp[1][0][1]=a[1];
    	dp[1][1][2]=b[1];
    	dp[1][2][4]=c[1];
    	for(int i=2;i<=n;i++){
    		add0(i);//选择a[i]加入
    		add1(i);//选择b[i]加入
    		add2(i);//选择c[i]加入
    	}
    	write(min(dp[n][0][7],dp[n][1][7],dp[n][2][7]));
    	flush();
    	return 0;
    }
    

      

  • 相关阅读:
    applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.
    HTML
    c# Path路径类
    C# 继承
    C# 结构体
    c# 类
    c#方法
    wpf开源控件MahApps.Metro
    c#数组类型
    c#类型转换
  • 原文地址:https://www.cnblogs.com/codetogether/p/13324736.html
Copyright © 2011-2022 走看看