A

B

C

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll mod = 3e7;
int pop = ;
char f[][];
int dp1[][];
int dp2[][];
string a;
int main()
{
int n, m, k;
cin >> n >> m >> k;
int anser = ;
char ch;
for (int i = ; i <= n; i++)
{
scanf("%s", f[i] + );
}
if (k == )
{
for (int i = ; i <= n; i++)
{
for (int j = ; j <= m; j++)
{
ch = f[i][j];
if (ch == '.')
{
anser++;
}
}
}
cout << anser << endl;
return ;
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= m; j++)
{
ch = f[i][j];
if (ch == '*')
{
dp1[i][j] = dp2[i][j] = ;
}
else
{
dp1[i][j] = dp1[i - ][j] + ;
dp2[i][j] = dp2[i][j - ] + ;
if (dp1[i][j] >= k)
{
anser++;
}
if (dp2[i][j] >= k)
{
anser++;
}
}
}
}
cout << anser << endl;
return ;
}

D

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll mod = 3e7;
int pop = ;
vector<int> tree[];
int visit[];
int vis[];
int dp[][];
int ans[];
int gone[];
int num[];
int aim[];
string a;
int anser = ;
int flag = ;
void dfs(int x)
{
gone[x] = ;
int len = tree[x].size();
for (int i = ; i < len; i++)
{
int to = tree[x][i];
if (gone[to] == )
{
cout << - << endl;
exit();
}
else if (gone[to] == )
{
for (int j = ; j < ; j++)
{
int add = num[x] == j;
dp[x][j] = max(dp[x][j], dp[to][j] + add);
}
}
else
{
dfs(to);
for (int j = ; j < ; j++)
{
int add = num[x] == j;
dp[x][j] = max(dp[x][j], dp[to][j] + add);
}
}
}
gone[x] = ;
}
int main()
{
int n, m;
int from, to;
cin >> n >> m;
cin >> a;
for (int i = ; i < a.size(); i++)
{
num[i + ] = a[i] - 'a';
dp[i + ][num[i + ]] = ;
}
for (int i = ; i <= m; i++)
{
scanf("%d %d", &from, &to);
tree[from].pb(to);
}
for (int i = ; i <= n; i++)
{
if (!gone[i])
{
dfs(i);
}
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= ; j++)
{
ans[i] = max(ans[i], dp[i][j]);
}
anser = max(anser, ans[i]);
}
cout << anser << endl;
return ;
}

Codeforces 919 行+列前缀和 树上记忆化搜索(树形DP)的更多相关文章

  1. 记忆化搜索(DFS+DP) URAL 1223 Chernobyl’ Eagle on a Roof

    题目传送门 /* 记忆化搜索(DFS+DP):dp[x][y] 表示x个蛋,在y楼扔后所需要的实验次数 ans = min (ans, max (dp[x][y-i], dp[x-1][i-1]) + ...

  2. 记忆化搜索(DFS+DP) URAL 1501 Sense of Beauty

    题目传送门 /* 题意:给了两堆牌,每次从首部取出一张牌,按颜色分配到两个新堆,分配过程两新堆的总数差不大于1 记忆化搜索(DFS+DP):我们思考如果我们将连续的两个操作看成一个集体操作,那么这个操 ...

  3. Codeforces Round #554 (Div. 2) D 贪心 + 记忆化搜索

    https://codeforces.com/contest/1152/problem/D 题意 给你一个n代表合法括号序列的长度一半,一颗有所有合法括号序列构成的字典树上,选择最大的边集,边集的边没 ...

  4. Codeforces Round #336 (Div. 2) D. Zuma 记忆化搜索

    D. Zuma 题目连接: http://www.codeforces.com/contest/608/problem/D Description Genos recently installed t ...

  5. Codeforces Round #406 (Div. 1) A. Berzerk 记忆化搜索

    A. Berzerk 题目连接: http://codeforces.com/contest/786/problem/A Description Rick and Morty are playing ...

  6. codeforces 793 D. Presents in Bankopolis(记忆化搜索)

    题目链接:http://codeforces.com/contest/793/problem/D 题意:给出n个点m条边选择k个点,要求k个点是联通的而且不成环,而且选的边不能包含选过的边不能包含以前 ...

  7. Codeforces Gym 191033 E. Explosion Exploit (记忆化搜索+状压)

    E. Explosion Exploit time limit per test 2.0 s memory limit per test 256 MB input standard input out ...

  8. CodeForces - 632E Thief in a Shop (FFT+记忆化搜索)

    题意:有N种物品,每种物品有价值\(a_i\),每种物品可选任意多个,求拿k件物品,可能损失的价值分别为多少. 分析:相当于求\((a_1+a_2+...+a_n)^k\)中,有哪些项的系数不为0.做 ...

  9. Codeforces Round #459 (Div. 2):D. MADMAX(记忆化搜索+博弈论)

    题意 在一个有向无环图上,两个人分别从一个点出发,两人轮流从当前点沿着某条边移动,要求经过的边权不小于上一轮对方经过的边权(ASCII码),如果一方不能移动,则判负.两人都采取最优策略,求两人分别从每 ...

随机推荐

  1. WikiData Processing

    WikiData Processing Data Accessing To download latest-all.json.bz2 on the page https://dumps.wikimed ...

  2. leetcode 140 单词拆分2 word break II

    单词拆分2,递归+dp, 需要使用递归,同时使用记忆化搜索保存下来结果,c++代码如下 class Solution { public: //定义一个子串和子串拆分(如果有的话)的映射 unorder ...

  3. tf工程化部署相关

    1.TensorFlow 模型保存/载入的两种方法 https://blog.csdn.net/thriving_fcl/article/details/71423039 [讲解清晰,2种方法都有缺陷 ...

  4. ControlTemplate in WPF —— DatePicker

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...

  5. C# 给某个方法设定执行超时时间-2

    var response = RunTaskWithTimeout<ReturnType>( (Func<ReturnType>)); /// <summary> ...

  6. WPF VLC客户端和SDK的简单应用

    VLC_SDK编程指南 VLC 是一款自由.开源的跨平台多媒体播放器及框架,可播放大多数多媒体文件,以及 DVD.音频 CD.VCD 及各类流媒体协议.它可以支持目前市面上大多数的视频解码,除了Rea ...

  7. 阶段3 2.Spring_04.Spring的常用注解_7 改变作用范围以及和生命周期相关的注解

    Scope 改成多例 PreDestory和PostConstruct PreDestory和PostConstruct这两个注解了解即可 增加两个方法,分别用注解 没有执行销毁方法. 如果你一个子类 ...

  8. ES6的对象属性简写

    在ES6中允许我们在设置一个对象的属性的时候不指定属性名. 不使用ES6: const name='Ming', age='18', city='Shanghai'; const student ={ ...

  9. 使用Nginx做WebSockets代理教程

    WebSocket 协议提供了一种创建支持客户端和服务端实时双向通信Web应用程序的方法.作为HTML5规范的一部分,WebSockets简化了开发Web实时通信程 序的难度.目前主流的浏览器都支持W ...

  10. MyBatis框架原理4:插件

    插件的定义和作用 首先引用MyBatis文档对插件(plugins)的定义: MyBatis 允许你在已映射语句执行过程中的某一点进行拦截调用.默认情况下,MyBatis 允许使用插件来拦截的方法调用 ...