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( ...
随机推荐
- LeetCode Weekly Contest 26
写的有点晚了. 我每次都是先看一下这里http://bookshadow.com/leetcode/的思路,然后再开始写我自己的. 1. 521. Longest Uncommon Subsequen ...
- element-ui 分页中的slot的用法(自定义分页显示内容)
官方给的简单的例子以及效果. 最后弄成的效果: 按照文档在layout 添加slot, 这几个参数可以随意调换位置,然后分页显示效果会根据调换的位置显示相应内容.
- All Metro Apps on Windows 8.1 Do Not Work
所有的Metro Apps不能够正常打开,表现为打开后自动最小化到任务栏,并且不能恢复正常状态.在Event Viewer\Application中相应的错误信息为: Activation of ap ...
- ansible upload
# 链接地址:https://www.cnblogs.com/xiaoxiaoleo/p/6626299.html # synchronize: 从拉取远程服务器文件,需要加mode: pull # ...
- JavaScript DOM 总结
一.DOM基础1.节点(node)层次Document--最顶层的节点,所有的其他节点都是附属于它的.DocumentType--DTD引用(使用<!DOCTYPE>语法)的对象表现形式, ...
- Android高效加载大图
通过BitmapFactory的decode方法设置特定的options缩小图片到指定尺寸 1:通过加载设置了只编码图片边界options的图片,获取原图的尺寸和类型 2:计算图片需要缩小的倍数 3: ...
- IE兼容opacity
filter:alpha(opacity=80); opacity: 0.57; /* Firefox, Safari(WebKit), Opera) filter: "alpha(opac ...
- 安装sublimeServer插件
1.安装目的 做练习在谷歌浏览器中遇到报错信息:axios.min.js:8 Failed to load file:///E:/%E8%87%AA%E5%AD%A6/vue%E5%AD%A6%E4% ...
- 编译qemu
el7上编译 git clone git://git.qemu-project.org/qemu.git ./configure --target-list=x86_64-softmmu --cpu= ...
- gud-cloud
架构:计算层:三台机器,包含处理器,内存条,外加一个64GB的存储器,这个存储器安装exsi主机,然后创建cvm虚拟机,硬盘空间选择在之前安装exsi主机的存储器里面 存储层:三台机器内置多个硬盘8T ...