srm 533
250
Description
给你一串数字序列,每次删掉第i个数。获得权值w[i−1]×w[i+1],求最后剩下第一个和最后一个数获得的最大权值和
Solution
简单dp,枚举断点就可以
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
typedef long long LL;
LL f[N][N];
vector<int> w;
LL dp(int l, int r) {
if (r - l == 1) return f[l][r] = 0;
LL &t = f[l][r];
if (~t) return t;
t = 0;
for (int i = l + 1; i < r; ++i) {
t = max(t, dp(l, i) + dp(i, r) + w[l] * w[r]);
}
return t;
}
class CasketOfStar {
public:
int maxEnergy(vector <int> weight) {
w = weight;
int n = weight.size();
memset(f, -1, sizeof(f));
return dp(0, n - 1);
}
};
500
Description:
给定一个字符矩阵。我们要按顺序取遍全部的”#”。规定操作顺序是取同行的一个”#”,再取同列的一个”#”,以此类推,问能不能取遍
Solution
非常easy反应到,这是一道欧拉回路的题,行列单独考虑。处理一些细节就能够了。注意到假设是欧拉通路的话起始点的问题就能够了。整体来说比較简单。
Code:
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int r[N], c[N];
bool ok[N][N], vis[N][N];
int n, m, tot;
void dfs(int x, int y) {
vis[x][y] = 1;
--tot;
for (int j = 0; j < m; ++j)
if (ok[x][j] && !vis[x][j]) dfs(x, j);
for (int i = 0; i < n; ++i)
if (ok[i][y] && !vis[i][y]) dfs(i, y);
}
class MagicBoard {
public:
string ableToUnlock(vector <string> board) {
n = board.size(), m = board[0].size();
int x, y;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
if (board[i][j] == '#') {
ok[i][j] = 1;
++r[i], ++c[j];
x = i, y = j;
++tot;
}
int rr = 0, cc = 0;
for (int i = 0; i < n; ++i) if (r[i] & 1) ++rr;
for (int j = 0; j < m; ++j) if (c[j] & 1) ++cc;
if (rr + cc > 2) return "NO";
if (rr + cc == 2 && !cc) return "NO";
dfs(x, y);
cout << tot << endl;
return tot ? "NO" : "YES";
}
}P;
int main() {
vector<string> s;
s.push_back("##"), s.push_back(".#");
P.ableToUnlock(s);
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
srm 533的更多相关文章
- 记第一次TopCoder, 练习SRM 583 div2 250
今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...
- SRM 513 2 1000CutTheNumbers(状态压缩)
SRM 513 2 1000CutTheNumbers Problem Statement Manao has a board filled with digits represented as St ...
- SRM 510 2 250TheAlmostLuckyNumbersDivTwo(数位dp)
SRM 510 2 250TheAlmostLuckyNumbersDivTwo Problem Statement John and Brus believe that the digits 4 a ...
- SRM 657 DIV2
-------一直想打SRM,但是感觉Topcoder用起来太麻烦了.题目还是英文,不过没什么事干还是来打一打好了.但是刚注册的号只能打DIV2,反正我这么弱也只适合DIV2了.. T1: 题目大意: ...
- SRM DIV1 500pt DP
SRM 501 DIV1 500pt SRM 502 DIV1 500pt SRM 508 DIV1 500pt SRM 509 DIV1 500pt SRM 511 DIV1 500pt SRM 5 ...
- TC srm 673 300 div1
TC srm.673 300 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 Description 给你n(n<=50)匹马和n个人,一匹马和一个人能 ...
- SRM 584 第一次玩TopCoder。。。只水题一道。。。
第一次topcoder,以前老感觉没有资格去做tc,cf什么的,现在已经慢慢接触了. 感觉还可以,还是有让我们这些蒻菜安慰的水题. tc的确很好玩,用客户端比赛,还有各种规则,而且还是只编写一个类提交 ...
- SRM 616 ColorfulCoins
题意:给定一个从小到大的货币面值,每一个面额都是其前面面额的倍数(倍数大于等于2),每一种货币面值对应一种颜色,目前不清楚面值与颜色的对应关系.要求用最少的查询次数来确定面额与颜色的对应关系.(一次查 ...
- SRM144 - SRM 148(少144-DIV1-LV3,147-DIV2-LV3)
SRM 144 DIV 1 500pt tag:组合 题意:彩票中奖.给定n, m,从1-n中选择m个数组成数列a1, a2, a3...am.对于数列{am}分别满足以下条件的概率: (1)数列所有 ...
随机推荐
- clearcase 中一些概念和操作
clearcase 中一些概念和操作 视图 常用命令 ClearCase 安装和使用的一些FAQ 参考 ClearCase具体的说是做配置管理的工具,只是SCM管理工具其中的一种.是RATIONAL公 ...
- html中的rowspan和colspan
摘自w3school(http://www.w3school.com.cn/tags/att_td_colspan.asp)colspan 属性规定单元格可横跨的列数.<table border ...
- PAIP: Paradigms of Artificial Intelligence Programming
PAIP: Paradigms of Artificial Intelligence Programming PAIP: Paradigms of Artificial Intelligence Pr ...
- javascript 下拉列表 自己主动取值 无需value
<select id="applyType" name="$!{status.expression}" class="inp" onc ...
- Android源代码分析-资源载入机制
转载请注明出处:http://blog.csdn.net/singwhatiwanna/article/details/23387079 (来自singwhatiwanna的csdn博客) 前言 我们 ...
- [Android学习笔记]自定义控件的使用
自定义控件时,最好抽象得彻底,并且编写需严谨,因为可能程序中多处都会引用到它,或者提供给团队中的其他人使用. 其一般步骤为: 1.创建控件的类文件,定义其功能逻辑.一般继承自现有控件或者View2.在 ...
- Mysql 导入导出数据结构及数据
方式一: mysqldump -ukevin -P3306 --default-character-set=utf8 -p -h10.1.15.123 activity sign_in_user &g ...
- hadoop集群空间使用情况报告脚本
近期集群空间有点紧张,总是操心空间不足而崩溃,近期扩容又不太现实,经与集群用户沟通发现:集群上存储了非常多没用的历史数据,能够删除,这样就能够通过一个crontab脚本每天生成集群空间使用报告,当使用 ...
- tomcat各版本和jsp、jstl、servlet的依赖关系(转)
Servlet / JSP / Tomcat Version Servlet/ JSP Tomcat 2.5/2.1 6.0.18 2.4/2.0 5.5.27 2.3/1.2 4.1.3 ...
- Burp Suite抓包、截包和改包
Burp Suite..呵呵.. 听说Burp Suite是能够监測.截取.改动我们訪问web应用的数据包,这么牛X? 条件:本地网络使用代理.由Burp Suite来代理.也就是说,每一个流出外网的 ...