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. Android Intent和IntentFilter详解与使用及实现系统“分享”接口

    Intent Android中提供了Intent机制来协助应用间的交互与通讯,Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描述,负责找到 ...

  2. 继成极光推送SDk的实现

    进入极光推送官网:https://www.jiguang.cn/push 注册,创建应用,申请APPKey等操作 代码实现: 确认android studio的 Project 根目录的主 gradl ...

  3. 零填充(Zero-padding)

    零填充(Zero-padding):有时,在输入矩阵的边缘使用零值进行填充,这样我们就可以对输入图像矩阵的边缘进行滤波.零填充的一大好处是可以让我们控制特征图的大小.使用零填充的也叫做泛卷积,不适用零 ...

  4. 连接Xshell

    连xshell之前先进入[root@localhost zxj]# vim /etc/ssh/sshd_config, 将115行删除注释改为UseDNS  no, 保存重启sshd(xshell)的 ...

  5. JS点击img图片放大再次点击缩小JS实现 简单实用Ctrl+C+V就可以用

    业务需要,从后台获取的图片列表,用img标签展示,用户需要查看大图.记录下来以便学习和参考.示例图如下: 放大之前: 放大之后: 点击后放大(由于图片高度超出了页面,需要通过overflow:auto ...

  6. Tensorflow 安装 和 初识

    Windows中 Anaconda,Tensorflow 和 Pycharm的安装和配置   https://blog.csdn.net/zhuiqiuzhuoyue583/article/detai ...

  7. 【Ruby on Rails 学习六】Ruby 类 的入门

    1.什么是类 2.类与实例的区别 3.自定义简单的类 生活中的垃圾分类,是集合上的概念 比如数学上的   1  a  2  b  c  4  5分类为数字1 2 4 5 ,字母  a  b  c ir ...

  8. Qt - 基于HTTP的网络编程

    HTTP(超文本传输协议 Hyper Text Transfer Protocol) 基于TCP/IP通信协议,属于应用层协议. 使用情况: HTTP是无连接(无连接的含义是限制每次连接只处理一个请求 ...

  9. 性能库 Oracle数据库 连接不上问题的解决

    今天性能库的centos 上面的oracle18c 数据库连接不上了 这里进行了一次简单处理 针对不同问题进行说明: 1. 实例时 blocked 的状态 问题现象: LSNRCTL> stat ...

  10. Mybatis(二) SQL映射文件

    SQL映射文件 单条件查询 1. 在UserMapper接口添加抽象方法 //根据用户名模糊查询 List<User> getUserListByName(); 2. 在UserMappe ...