码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 10593 Kites DP

时间:2016-01-05 18:30:18      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

The season of ?ying 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 ?gure ?rst 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 ?le.
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;
}
代码

 

UVA 10593 Kites DP

标签:

原文地址:http://www.cnblogs.com/zxhl/p/5102933.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!