zoukankan      html  css  js  c++  java
  • CF1110D Jongmah

    The (sougoupinyin) on my laptop has been broken for several days, which drives me crazy. Then I realized I can avoid Chinese if I wanted. So here comes a new try with my (piejiao) English.

    [CF1110D] Jongmah , Luogu
    Calculate the maximum number of triples when using (n) numbers given, which also meets (a_i le m).
    Illegal triples include (Chi(i, i + 1. i + 2)) and (Peng(i, i, i)).
    $n, m le 10^6 $.

    **Suppose (dp[i][j][k]) represents the maximum triples at i, having j times ([i - 1, i, i + 1]), k times ([i, i + 1, i + 2]). **
    Enumerating j,k,l from 0 to 2, here comes the equation:
    (chkmax(dp[i][k][l], dp[i - 1][j][k] + (cnt[i] - j - k - l) / 3 + l);) // starts with i, contributes l.
    The answer is (dp[m][0][0]).

    (O(n))

    Summary
    Individually considering every state, which was my first idea, remains a mess. The key is how to calculate the contribution created now. One possible solution is to transfer (Chi), add (Peng). Adding (Peng) refers to i, don't forget to add (l) due to (Chi) starts with i.

    Finally we all realize that Chinese is so brief, compared with English's stinky and long. It also reflects why Chinese (teenagers) achieve higher grades than teenagers in EUR&USA. However, we have to use English one day.

    #include<cstdio>ss
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define debug(...) fprintf(stderr,__VA_ARGS__)
    #define Debug(x) cout<<#x<<"="<<x<<endl
    using namespace std;
    typedef long long LL;
    const int INF=1e9+7;
    inline LL read(){
    	register LL x=0,f=1;register char c=getchar();
    	while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
    	while(c>=48&&c<=57)x=(x<<3)+(x<<1)+(c&15),c=getchar();
    	return f*x;
    }
    
    const int N = 1e6 + 5;
    
    int dp[N][3][3], cnt[N];
    int n, m;
    
    inline void chkmax(int& a, int b){ a = a > b ? a : b; }
    
    int main(){
    	n = read(), m = read();
    	for(int i = 1; i <= n; ++i) ++cnt[read()];
    	memset(dp, -1, sizeof dp);
    	dp[0][0][0] = 0;
    	for(int i = 1; i <= m; ++i)
    		for(int j = 0; j < 3; ++j)
    			for(int k = 0; k < 3; ++k)
    				for(int l = 0; l < 3; ++l){
    					if(j + k + l > cnt[i]) continue;
    					chkmax(dp[i][k][l], dp[i - 1][j][k] + (cnt[i] - j - k - l) / 3 + l); // starts with i, contributes l.
    				}
    	printf("%d
    ", dp[m][0][0]);
    }
    
  • 相关阅读:
    github release 文件下载贼慢,干脆失败的解决方法
    windows 下sublime text 3 配置python 环境详解
    Ubuntu下安装并使用sublime text 3(建议:先安装Package controls 后在看本教程,否则可能会安装不了)
    将博客搬至CSDN
    signalr core客户端通过ssl连接服务的方式
    解决html导出pdf中文乱码问题的正确姿势
    记一次asp.net core 在iis上运行抛出502.5错误
    Elasticsearch 集群搭建
    bower私服部署
    体验Code::Blocks下的Windows GUI编程(32 bit and 64 bit)
  • 原文地址:https://www.cnblogs.com/lizehon/p/11239365.html
Copyright © 2011-2022 走看看