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. 康少带你玩转JavaScript

    目录 1.JavaScript简述 2.JavaScript引入方式 3.JavaScript语法基础 4.JavaScript数据类型 5.运算符 6.流程控制 7.函数 8.内置对象和方法 1.J ...

  2. guice基本使用,三种注入方式(二)

    guice提供了强大的注入方式. 1.属性注入 2.构造器注入 3.set方式注入 1.属性注入: package com.ming.user.test; import com.google.inje ...

  3. 织梦忘记密码DedeCMS密码重设工具radminpass找回密码

    本工具是用于新人忘记管理员密码重设所制作,只需要将radminpass.php文件拷贝到根目录,运行“http://yousite/radminpass.php(yousite为网站域名)”,按照操作 ...

  4. python爬虫:爬取凤凰指数

    在知乎上看到的这个问题,讲讲我爬取过程中遇到的问题: 1.循环爬取其他页面,在其他项目中用循环一般可以搞定,可是这个,第一页和第二第三页的表格是不同的,所以要重新写规则,我懒,写了第一页后,就不想在写 ...

  5. 我的wordpress在Nginx的配置

    lnmp生成过程 You select the exist rewrite rule:/usr/local/nginx/conf/wordpress.conf Gracefully shutting ...

  6. java学习笔记5——String类常用方法

    1.字符串长度计算: int i = String1.length(); 2.字符串比较:1) equals()和equalsIgnoreCase //比较两个字符串对象的实体是否相同,相同输出tru ...

  7. H3C三层交换机S5500初始配置+网络访问策略

    DHCP中继配置命令 dhcp relay address-check enable 命令用来使能DHCP 中继的地址匹配检查功能. undo dhcp relay address-check ena ...

  8. JDBC连接MySQL数据库(一)——数据库的基本连接

    JDBC的概念在使用之前我们先了解一下JDBC的概念, JDBC的全称是数据库连接(Java Database Connectivity),它是一套用于执行SQL语句时的API,应用程序可以通过这套A ...

  9. RemoveAll测试

    foreach (var item in procode) { var reslit = LoadData((string)item.ProductCode.Trim(), item.product_ ...

  10. 路飞学城Python-Day137

    django项目二 个人博客系统 github地址:https://github.com/pandaboy1123/cnblog