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( ...
随机推荐
- Spring《八-一》CGLIB代理和自动代理
CGLIB代理 配置文档 <bean id="logProxy" class="org.springframework.aop.framework.ProxyFac ...
- C#中关于XML与对象,集合的相互转换
XML与对象,集合的相互转化 今天小伙伴在群里问了一下关于XML与对象之间的相互转换,作为菜鸟的我正好趁着闲着的时间学习了一波,直接上代码了,有疑问或者有错误的地方还请大家指正,谢谢.... usin ...
- oracle scott趣事
Oracle里面是scott是个什么用户呢? 这个就要追朔到Oracle的创业阶段了, 1977年6月,埃里森,Bob Miner和Ed Oates在硅谷共同创办了一家名为软件开发实验室(Softwa ...
- WordPress的wordfence插件的设置方法
- 关于编译PCL1.71
最近在编译PCL1.71时总会出现错误, 编译的时候就出现无法生成pcl_io_debug.lib 由于无法生成pcl_io_debug.lib,. 借鉴PCL中国的经验: (1):把io\inclu ...
- RabbitMQ学习之集群镜像模式配置
1.增加负载均衡器 关于负载均衡器,商业的比如F5的BIG-IP,Radware的AppDirector,是硬件架构的产品,可以实现很高的处理能力.但这些产品昂贵的价格会让人止步,所以我们还有软件负载 ...
- linux下的头文件和库文件搜索路径 (转)
GCC 找头文件有三种策略: 1. 会在默认情况下指定到 /usr/include 文件夹 ( 更深层次的是一个相对路径, GCC 可执行程序的路径是 /usr/bin ,那么它在实际工作时指定头文 ...
- java并发的一些杂乱小结
1.java语言本身就提供了多线程机制,这样即使在单任务的操作系统上也可以实现多线程,这也是java语言本身"编写一次,到处运行"的特性. 2.并发要解决的问题本质上是:多个线程同 ...
- 10件5G能实现,但4G不能做的事情
10件5G能实现,但4G不能做的事情 从三星Galaxy S10 5G手机到OnePlus 7 Pro 5G手机以及更高版本,首批5G手机现已上市.5G网络时代的开启是从小范围内,如果你居住在可以使用 ...
- win10更新后程序路径盘符变成*星号解决方法
发现这个问题是当我在命令行里输入java -version时提示 找不到*:\Program Files\Java...之类的 怎么好好的D:\Program Files\Java变成了*:\Prog ...