Codeforces Round #662 (Div. 2) D. Rarity and New Dress
程序员文章站
2022-03-21 22:29:53
题目链接思路:定义f[i][j]为以(i,j)为最下边的菱形的最大边长,那么很明显答案就是∑f[i][j]。代码:#include#define int long long#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);const int N=1e5+3;const int M=2e4+5;const double eps=1e-8;const int mod=9982...
题目链接
思路:
定义f[i][j]为以(i,j)为最下边的菱形的最大边长,那么很明显答案就是∑f[i][j]。
代码:
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=1e5+3;
const int M=2e4+5;
const double eps=1e-8;
const int mod=998244353;
const int inf=0x7fffffff;
const double pi=3.1415926;
using namespace std;
int f[2005][2005];
char s[2005][2005];
signed main()
{
IOS;
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>s[i]+1;
}
int ans=0;
for(int ch=0;ch<26;ch++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(s[i][j]==ch+'a')
{
f[i][j]=1;
}
else
{
f[i][j]=0;
}
if(i>=3)
{
int num=min(min(f[i-1][j],f[i-1][j-1]),min(f[i-2][j],f[i-1][j+1]));
if(num!=0&&f[i][j]!=0)
{
f[i][j]=max(f[i][j],num+1);
}
}
ans+=f[i][j];
}
}
}
cout<<ans<<endl;
return 0;
}
本文地址:https://blog.csdn.net/ACkingdom/article/details/107888771
推荐阅读
-
Educational Codeforces Round 97 (Rated for Div. 2) D. Minimal Height Tree
-
Codeforces Round #665 (Div. 2) D. Maximum Distributed Tree(dfs)
-
Codeforces Round #619 (Div. 2) D. Time to Run
-
Codeforces Round #583 (Div. 1 + Div. 2,) D. Treasure Island(dfs+思维)
-
Codeforces Round #533 (Div. 2) D. Kilani and the Game(bfs+模拟)
-
Codeforces Round #643 (Div. 2) D. Game With Array
-
Codeforces Round #459 (Div. 2):D. MADMAX(记忆化搜索+博弈论)
-
Codeforces Round #260 (Div. 2) D. A Lot of Games(树上博弈)
-
Codeforces Round #662 (Div. 2) D. Rarity and New Dress
-
Codeforces Round #658 (Div. 2) D. Unmerge(dp,01背包)