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. C++面向对象实践

    实践如下: class Person{ private: int age; ]; int hight; public: Person(int age, int hight, char* name); ...

  2. 搭建SVN服务器时报错:0x80004002

    一.错误信息 Cannot query proxy blanket: no such interface supported (0x80004002) 二.解决方案 这个错误只会在有NVIDIA独立显 ...

  3. 代码实现:一个数如果恰好等于它的因子之和,这个数就称为"完数"。例如6=1+2+3.第二个完全数是28, //它有约数1、2、4、7、14、28,除去它本身28外,其余5个数相加, //编程找出1000以内的所有完数。

    import java.util.ArrayList; import java.util.List; //一个数如果恰好等于它的因子之和,这个数就称为"完数".例如6=1+2+3. ...

  4. 第八章 SpringCloud之Feign、Hystrix结合使用

    #这个章节主要是针对Hystrix的使用,因为Feign的章节在上一节已经实现了,整个代码也是在上一个章节的基础上修改的 ##################Hystrix一个简单Demo实现#### ...

  5. java里poi操作excel的工具类(兼容各版本)

    转: java里poi操作excel的工具类(兼容各版本) 下面是文件内具体内容,文件下载: import java.io.FileNotFoundException; import java.io. ...

  6. zabbix服务器性能监控工具的安装一

    Linux下安装zabbix需要有LNMP运行环境,本篇记录安装LNMP的过程 目录 1.准备工作 2.安装mysql 3.安装nginx 4.安装php 1.准备工作 1.1准备一台centos6. ...

  7. DSP28335 GPIO学习

    根据网络资料以及以下两篇博客整理 http://blog.sina.com.cn/s/blog_86a6035301017rr7.html http://blog.csdn.net/hmf123578 ...

  8. kettle 连接 mysql8.0 报错的解决办法 org.pentaho.di.core.exception.KettleDatabaseException: Error occurred while trying to connect to the database Error connecting to database: (using class org.gjt.mm.mysql.

    1.下载 mysql8.0 驱动放到 如下目录中 mysql8.0以上的驱动下载链接:mysql-connet-8.0.13 2.配置你连接的数据库 找到如下文件打开编辑 连接信息:下面是我本地的配置 ...

  9. python 并发编程 协程 greenlet模块

    一 greenlet模块 不敢是yield,还是greenlet都没有实现检测io,实现遇到io切换效果 如果我们在单个线程内有20个任务,要想实现在多个任务之间切换,使用yield生成器的方式过于麻 ...

  10. 一些常用的字符串函数(CLR函数)

    原代码来自:东莞--小小大神 使用 --聚合函数 SELECT father_key,dbo.String_Agg(department_name) FROM dbo.b_department GRO ...