zoukankan      html  css  js  c++  java
  • codefoces 1393D Rarity and New Dress

    https://codeforces.com/contest/1393/problem/D

    矩阵dp,数有几个菱形,一般好像就是以某个位置为底,然后去dp

    具体看代码吧,没啥可说的 ,都是玄学dp

    #include<iostream>
    #include<cstring>
    using namespace std;
    typedef long long ll;
    const int maxn = 2020;
    char map[maxn][maxn];
    ll dp[maxn][maxn];
    int cal(int i,int j){
    	char ch = map[i][j];
    	if(ch != map[i-1][j-1] || ch != map[i-1][j+1] || ch != map[i-1][j] || ch != map[i-2][j]) return 0;
    	return 1;
    }
    int main() {
    	int n,m;
    	cin>>n>>m;
    	for(int i=0; i<n; i++) {
    		scanf("%s",map[i]);
    	}
    
    	for(int i=0; i<n; i++) {
    		for(int j=0; j<m; j++) {
    			if(i <= 1 || j == 0 || j == m-1 ) {
    				dp[i][j] = 1;
    			} 
    			else {
    				if(cal(i,j)){
    					dp[i][j] = min(dp[i-1][j-1] ,min(dp[i-1][j+1],dp[i-2][j]))+1;
    				}
    				else{
    					dp[i][j] = 1;
    				}
    			}
    		}
    	}
    	ll ans = 0;
    	for(int i=0; i<n; i++) {
    		for(int j=0; j<m; j++) {
    		//	if(dp[i][j] == 0) dp[i][j] = 1;
    			ans += dp[i][j];
    		//	cout<<dp[i][j]<<" ";
    		}
    		//cout<<endl;
    	}
    	cout<<ans<<endl;
    	return 0;
    }
    

      

    寻找真正的热爱
  • 相关阅读:
    AI
    CentoOS6.6安装netcat
    ip防刷脚本
    php git pull
    冥想_ PHP抽奖程序概率算法
    如何在CentOS配置Apache的HTTPS服务
    C++ 用RGB 三种颜色绘图
    Linux Vsftpd 连接超时解决方法(被动模式)
    js 函数返回函数
    模拟jquery的$()选择器的实现
  • 原文地址:https://www.cnblogs.com/lesning/p/13695215.html
Copyright © 2011-2022 走看看