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的更多相关文章

  1. UVA.10192 Vacation (DP LCS)

    UVA.10192 Vacation (DP LCS) 题意分析 某人要指定旅游路线,父母分别给出了一系列城市的旅游顺序,求满足父母建议的最大的城市数量是多少. 对于父母的建议分别作为2个子串,对其做 ...

  2. UVA.10130 SuperSale (DP 01背包)

    UVA.10130 SuperSale (DP 01背包) 题意分析 现在有一家人去超市购物.每个人都有所能携带的重量上限.超市中的每个商品有其相应的价值和重量,并且有规定,每人每种商品最多购买一个. ...

  3. 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 ...

  4. UVa 10029 hash + dp

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  5. uva 10154 贪心+dp

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  6. UVA 1358 - Generator(dp+高斯消元+KMP)

    UVA 1358 - Generator option=com_onlinejudge&Itemid=8&page=show_problem&category=524& ...

  7. uva 1534 - Taekwondo(dp+馋)

    题目连接:uva 1534 - Taekwondo 题目大意:有两组什么东西,题目背景有点忘记了,就是给出两组数,两组个数分别为n,m,要求找出min(n,m)对数.每一个数最多最多选一次,使得这mi ...

  8. uva 10118(DP)

    UVA 10118 题意: 有4堆糖果,每堆有n(最多40)个,有一个篮子,最多装5个糖果,我们每次只能从某一堆糖果里拿出一个糖果, 如果篮子里有两个相同的糖果,那么就可以把这两个(一对)糖果放进自己 ...

  9. UVA 1626 区间dp、打印路径

    uva 紫书例题,这个区间dp最容易错的应该是(S)这种匹配情况,如果不是题目中给了提示我就忽略了,只想着左右分割忘记了这种特殊的例子. dp[i][j]=MIN{dp[i+1][j-1] | if( ...

随机推荐

  1. CTF-Mayday

    打开下载的Mayday.txt文件: 温柔 知足突然好想你  拥抱突然好想你  拥抱温柔 知足温柔 知足突然好想你  拥抱突然好想你  拥抱温柔 知足温柔 知足突然好想你  拥抱突然好想你  拥抱温柔 ...

  2. MAVEN 杂记

    MAVEN中央仓库 http://repo.maven.apache.org/maven2http://repo1.maven.org/maven2/http://mvnrepository.com/ ...

  3. 利用jquery的ajaxPrefilter阻止重复发送请求

    利用jquery的ajaxPrefilter阻止重复发送请求 (function ($) { var pendingRequests = {}; // 所有ajax请求的通用前置filter $.aj ...

  4. 第5章分布式系统模式 在 .NET 中使用 DataSet 实现 Data Transfer Object

    要在 .NET Framework 中实现分布式应用程序.客户端应用程序需要显示一个窗体,该窗体要求对 ASP.NET Web Service 进行多个调用以满足单个用户请求.基于性能方面的考虑,我们 ...

  5. DB2大数据量优化查询解决方案

    利用DB2表分区的功能对大数据量的表进行分区,可以优化查询. 表分区介绍: 表分区是一种数据组织方案,它根据一列或多列中的值把表数据划分为多个称为数据分区 的存储对象. (我觉得表分区就类似于Wind ...

  6. AVD的Hardware选项

    最近学习开发游戏,需要GLES2.0使用,使用Android虚拟机调试一直报错闪退.百度说Android 4.0及以后的版本[使用API15及以上]),已经支持GLES2.0,需要在HardWare选 ...

  7. Linux学习之路三:重要概念之Linux系统层次结构

    上图来自Unix编程圣经<APUE>英文第二版.如图,处于最中心的是系统内核,负责机器硬件资源管理,进程管理等:shell,函数库(值得记住的是C标准函数库)和某些应用程序均直接构建于内核 ...

  8. linux VFS 之一 :虚拟文件系统的面向对象设计思想

    VFS的面向对象的思想,如下图: VFS在上层用户空间的进程与底层特定文件系统之间起到一个承上启下的作用, 对上:封装标准的系统调用接口给用户空间app,user space app不必关心特定文件系 ...

  9. win 2016 添加系统组件注册表,

    Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ServerManager\ServicingS ...

  10. C# switch 语句

    switch ("MySql") //选择语句 // case语句 成对 结束 执行到 第一个break { case "SqlServer2000": cas ...