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. 方差分析(python代码实现)

    python机器学习-乳腺癌细胞挖掘(欢迎关注博主主页,学习python视频资源,还有大量免费python经典文章) https://study.163.com/course/introduction ...

  2. Selenium-WebDriverApi接口

    webdriver获取元素的18种方式: 1.单数模式8 种 id定位模式 element = driver.find_element_by_id('i1') element.send_keys('U ...

  3. jenkins提示反向代理设置有误

    jenkins提示反向代理设置有误 参照地址 https://www.cnblogs.com/yhleng/p/7594892.html 分析:是junkins的url地址填错了 解决: 系统管理-- ...

  4. python-unittest模块中的各类断言

    unittest中断言主要有三种类型: 基本的布尔断言,即:要么正确,要么错误的验证 比较断言,如比较两个变量的值(跟上面的布尔断言区别不大,主要是通过比较两个变量的值得出布尔值) 复杂断言(一般用的 ...

  5. cocos2dx[3.2](5) 屏幕适配

    1.两个分辨率 1.1.窗口分辨率 在AppDelegate.cpp中有个设置窗口分辨率的函数.该函数是设置了我们预想设备的屏幕大小,也就是应用程序窗口的大小. // glView->setFr ...

  6. Linux man及echo的使用

    学习目标: 通过本实验掌握man和echo两个命令的用法. 实验步骤: 1.通过man查询ls的详细用法,后面可以跟哪些参数,每个参数的作用.这里主要查找如何禁止ls彩色结果输出. 2.把查找到的参数 ...

  7. noi.ac-CSP模拟Day5T2 灯

    算是一道思维题吧,没有什么算法在里面. 之前想的是,能走的话就尽量走远,走过去开灯然后再回去关灯,然后再走,每一段路要走3次. 然而,“能走的话就尽量走远”只是yy的一个贪心,没有任何依据.假设在中间 ...

  8. 【嵌入式开发】树莓派+官方摄像头模块+VLC串流实时输出网络视频流

    sudo apt-get update sudo apt-get install vlc sudo raspivid -o - -t 0 -w 640 -h 360 -fps 25|cvlc -vvv ...

  9. bi的tableau

    参考: 官网: https://help.tableau.com/current/server-linux/zh-cn/get_started_server.htm 可视化分析最佳做法: 实用指南 h ...

  10. Windows2012r2 安装SQLSERVER2017 与 SQLSERVER2016 的错误提示解决KB2919355 以及 KB2919442

    1. win2012r2 安装时 总是提示: 然后费了半天劲 下载下来又提示 找了一下 需要先安装这么一个补丁才可以 KB2919442 然后才能安装上 KB2919355 然后就可以正常安装了: