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=550;
const ll INF = 1ll<<61;
const int inf = 1000000007;
const int MOD =   2000000011;

char mp[N][N];
int dp[N][N],n;
int solve() {
    int ans = 0;
    mem(dp);
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++) {
            if(mp[i][j] == 'x') {
                int tmp = min(dp[i-1][j],dp[i][j-1]);
                dp[i][j] = tmp + (mp[i-tmp][j-tmp] == 'x');
                if(dp[i][j] > 1) ans +=dp[i][j] - 1;
            }
        }
    }
    mem(dp);
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++) {
            if(mp[i][j] == 'x') {
                int tmp = min (dp[i-1][j-1],dp[i-1][j+1]);
                if(tmp == 0 || mp[i-1][j] != 'x')  dp[i][j] = 1;
                else if(mp[i- 2*tmp][j]=='x' && mp[i-tmp*2+1][j] == 'x') dp[i][j] = tmp + 1;
                else dp[i][j] = tmp;
                if(dp[i][j] > 1) ans +=dp[i][j] - 1;
            }
        }
    }
    return ans;
}
int main() {
    while(scanf("%d",&n)!=EOF) {
        for(int i=1;i<=n;i++) {
            getchar();
            for(int j=1;j<=n;j++) scanf("%c",&mp[i][j]);
        }
        printf("%d\n",solve());
    }
    return 0;
}
代码

 

转载于:https://www.cnblogs.com/zxhl/p/5102933.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值