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]);
    }
    
  • 相关阅读:
    python os模块 常用命令
    将excel表格中的数据导入到SQL中
    临时数据表DataTable selected方法的使用
    ASP.NET数据库使用精典读取数据库中数据
    新兵开唱
    DropDownList控件的changed事件调用
    C# 读取Excel表格中的数据
    C# 强制类型转换示例
    用ADO.NET的ExecuteScalar方法返回单一值
    CentOS 6.3 桥接上网
  • 原文地址:https://www.cnblogs.com/lizehon/p/11239365.html
Copyright © 2011-2022 走看看