• CF1420E Battle Lemmings


    CF1420E Battle Lemmings

    大菜鸡参考了两位哥哥的博客才写出来的

    zqy1018

    夕林山寸

    //Proudly using c++11 by gwt 
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef long double ld;
    typedef pair<int,int> pii;
    #define pb push_back
    #define eb emplace_back
    #define mp make_pair
    #define fi first
    #define se second
    #define all(x) (x).begin(),(x).end()
    //#define endl '
    '
    #define count2(x) __builtin_popcount(x)
    #define countleadingzero(x) __builtin_clz(x)
    #define debug(x) cerr << #x << " = " << x << endl;
    inline ll read(){//not solve LLONG_MIN LMAX=9,223,372,036,854,775,807
        ll s=0,w=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
        while(ch>='0' && ch<='9')s=s*10+ch-'0',ch=getchar();
        return s*w;
    }
    int dp[81][81][81*41];
    // ijk i in pos j cost k
    // show the minnimize numbers of part i "0..0"
    int main(){
    	int n;
    	cin>>n;
    	vector<int>nums(n+1);
    	int tot1=0; 
    	vector<int>pos1;
    	for(int i=1;i<=n;++i){
    		cin>>nums[i];
    		if(nums[i]==1)pos1.pb(i);
    	}
    	int sum=0;
    	tot1=pos1.size();
    	sum+=n*(n-1)/2;//every pair of n;
    	sum-=tot1*(tot1-1)/2;//every pair of 11
    	sum-=tot1*(n-tot1);//every pair of 10/01
    	int cost=0;
    	memset(dp,0x3f,sizeof(dp));
    	dp[0][0][0]=0;
    	for(int i=0;i<pos1.size();++i){
    		if(i==0)
    		cost+=max(0,(pos1[i]-1)*(pos1[i]-2)/2);
    		else
    		cost+=max(0,(pos1[i]-pos1[i-1]-1)*(pos1[i]-pos1[i-1]-2)/2);
    		dp[i+1][pos1[i]][0]=cost;
    		//cout<<cost<<'
    ';
    	}
    	int i=0;
    	const int MAXM=n*(n-1)/2;
    	for(auto posi:pos1){
    		i++;
    		for(int j=1;j<=n;++j){
    			for(int t=0;t<j;++t){
    				for(int k=0;k<=MAXM;++k){
    					int &PT=dp[i][j][abs(j-posi)+k];
    					PT=min(PT,dp[i-1][t][k]+max(0,(j-t-1)*(j-t-2)/2));
    				}
    			}
    		}
    //		cout<<cnt1<<' '<<tot1<<'
    ';
    	}
    	int ans=1e9;
    	for(int k=0;k<=MAXM;++k){
    		for(int j=1;j<=n;++j){
    			//sum-pastito
    //			cout<<dp[tot1][j][k]<<" ";
    			ans=min(ans,dp[tot1][j][k]+max(0,(n-j)*(n-j-1)/2));
    //			cout<<ans<<'
    ';
    		}
    //		cout<<endl;
    		if(tot1==0)
    		sum=ans;
    		cout<<sum-ans<<" 
    "[k==MAXM];
    	}
    //	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    	return 0;
    }
    
    
    
  • 相关阅读:
    vs2010使用刚刚配置好的STLport提示检测到"_MSC_VER”的不
    UltraISO制作Linux启动盘
    RedHat 简易配置 VNC Server 与VNC View详细说明!
    数据库中树状关系(各种树状分类)的查找
    java–jsp & javabean
    linux 下android的一键root
    MySQL简明教程及表设计原则
    Activity 生存周期
    java web EL表达式
    ubuntu下调试android手机,并进入手机shell终端
  • 原文地址:https://www.cnblogs.com/passguan/p/13755205.html
Copyright © 2020-2023  润新知