UVA 10593 Kites DP
The season of flying kites is well ahead. So what? Let us make an inventory for kites. We are given
a square shaped sheet of paper. But many parts of this are already porous. Your challenge here is to
count the total number of ways to cut a kite of any size from this sheet. By the way, the kite itself
can’t be porous :-) AND . . . it must be either square shaped or diamond shaped.
x
x xxx xxx xxx
xxx xxxxx xxx x.x x
x xxx xxx xxx
x
In the above figure first three are valid kites but not next two.
Input
Input contains an integer n (n ≤ 500), which is the size of the sheet. Then follows n lines each of which
has n characters (‘x’ or ‘.’). Here the dotted parts resemble the porous parts of the sheet. Input is
terminated by end of file.
Output
Output is very simple. Only print an integer according to the problem statement for each test case in
a new line.
Sample Input
4
.xx.
xxxx
.xx.
.x..
3
xxx
xxx
xxx
Sample Output
4
6
题意:给你一个 n*n的图,让你在图中找出x组成的边长大于等于2的菱形或正方
题解:DP ,这个博客的图比较好
http://blog.csdn.net/u012596172/article/details/41171815
//meek
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include<map>
#include<queue>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair const int N=;
const ll INF = 1ll<<;
const int inf = ;
const int MOD = ; char mp[N][N];
int dp[N][N],n;
int solve() {
int ans = ;
mem(dp);
for(int i=;i<=n;i++) {
for(int j=;j<=n;j++) {
if(mp[i][j] == 'x') {
int tmp = min(dp[i-][j],dp[i][j-]);
dp[i][j] = tmp + (mp[i-tmp][j-tmp] == 'x');
if(dp[i][j] > ) ans +=dp[i][j] - ;
}
}
}
mem(dp);
for(int i=;i<=n;i++) {
for(int j=;j<=n;j++) {
if(mp[i][j] == 'x') {
int tmp = min (dp[i-][j-],dp[i-][j+]);
if(tmp == || mp[i-][j] != 'x') dp[i][j] = ;
else if(mp[i- *tmp][j]=='x' && mp[i-tmp*+][j] == 'x') dp[i][j] = tmp + ;
else dp[i][j] = tmp;
if(dp[i][j] > ) ans +=dp[i][j] - ;
}
}
}
return ans;
}
int main() {
while(scanf("%d",&n)!=EOF) {
for(int i=;i<=n;i++) {
getchar();
for(int j=;j<=n;j++) scanf("%c",&mp[i][j]);
}
printf("%d\n",solve());
}
return ;
}
代码
UVA 10593 Kites DP的更多相关文章
- UVA.10192 Vacation (DP LCS)
UVA.10192 Vacation (DP LCS) 题意分析 某人要指定旅游路线,父母分别给出了一系列城市的旅游顺序,求满足父母建议的最大的城市数量是多少. 对于父母的建议分别作为2个子串,对其做 ...
- UVA.10130 SuperSale (DP 01背包)
UVA.10130 SuperSale (DP 01背包) 题意分析 现在有一家人去超市购物.每个人都有所能携带的重量上限.超市中的每个商品有其相应的价值和重量,并且有规定,每人每种商品最多购买一个. ...
- BZOJ 1260&UVa 4394 区间DP
题意: 给一段字符串成段染色,问染成目标串最少次数. SOL: 区间DP... DP[i][j]表示从i染到j最小代价 转移:dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k ...
- UVa 10029 hash + dp
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- uva 10154 贪心+dp
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 1358 - Generator(dp+高斯消元+KMP)
UVA 1358 - Generator option=com_onlinejudge&Itemid=8&page=show_problem&category=524& ...
- uva 1534 - Taekwondo(dp+馋)
题目连接:uva 1534 - Taekwondo 题目大意:有两组什么东西,题目背景有点忘记了,就是给出两组数,两组个数分别为n,m,要求找出min(n,m)对数.每一个数最多最多选一次,使得这mi ...
- uva 10118(DP)
UVA 10118 题意: 有4堆糖果,每堆有n(最多40)个,有一个篮子,最多装5个糖果,我们每次只能从某一堆糖果里拿出一个糖果, 如果篮子里有两个相同的糖果,那么就可以把这两个(一对)糖果放进自己 ...
- UVA 1626 区间dp、打印路径
uva 紫书例题,这个区间dp最容易错的应该是(S)这种匹配情况,如果不是题目中给了提示我就忽略了,只想着左右分割忘记了这种特殊的例子. dp[i][j]=MIN{dp[i+1][j-1] | if( ...
随机推荐
- CMD-echo
echo 打印 <> echo ^< echo ^> echo 换行 echo 你好@echo.世界. echo 多行打印 > log.log 此时 > 无效.(我 ...
- ABP框架应用汇总
相信很多人可能听过或没听过ABP这个框架,在我接触此框架时也是在现在所在的公司开始接触的,我们用此开源框架作为我们项目的架构,我们正好做的是Saas云服务多租户管理系统开发,并且经过了一年多高 ...
- VPU硬编码
平台是RK3066(福州瑞芯微公司),android 4.2.0,其实时VP8硬编码,与软件编码是ffpmeg,x264,xvid等软编码是有区别的.硬编码主要是依赖于硬件. 硬编码:通过调用Andr ...
- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build*解决办法
easy_install -U setuptools or pip install ipython 亲测有效
- c# 异步任务队列(可选是否使用单线程执行任务,以及自动取消任务)
使用demo,(.net framework 4.0 自行添加async wait 扩展库) class Program { static void Main(string[] args) { Con ...
- Sql Server 优化----SQL语句的执行方式与锁以及阻塞的关系
阻塞原因之一是不同的Session在访问同一张表的时候因为不兼容锁的原因造成的, 当前执行的SQL语句是否被阻塞(或者死锁),不仅跟当前表上的已有的锁有关,也会跟当前执行的SQL语句的执行方式有关 简 ...
- 【Oracle】RAC集群中的命令
数据库名称:racdb 节点名称:rac3.rac4 注:以下命令均在grid用户中执行 1.查看集群节点的状态: [grid@rac3 ~]$ crsctl check cluster [grid@ ...
- 【Oracle】非RMAN恢复数据文件、控制文件
实验环境:OEL 5.6 oracle 11g(11.2.0.4.0) 注意: system表空间数据文件不能在线recover,需要启动到mount状态再recover: undo表空间数据文件可以 ...
- Boost锁~临界区保护和临界资源共享
前言: 除了thread,boost::thread另一个重要组成部分是mutex,以及工作在mutex上的boost::mutex::scoped_lock.condition和barrier,这些 ...
- 关于《Python核心编程》第2版和第3版
关于<Python核心编程>第2版和第3版 以前开始学Python的时候,根据某大神的建议买了本<Python核心编程>第2版,慢慢学习.而最近回家没带书回来,刚好JD有活动, ...