UVA 10593 Kites DP

Source: Internet
Author: User

The season of Ying Kites is a well ahead. So what? Let us make a inventory for kites. We are given
A square shaped sheet of paper. But many parts of this is already porous. Your Challenge here's to
The count of the total number of ways to cut a kite of any size from this sheet. By 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 is valid kites but not next.
Input
Input contains an integer n (n≤500), which is the size of the sheet. Then follows n lines each of the 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 a 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

Test Instructions : give you a n*n figure that lets you figure out the X-shaped side of the graph and grow to a diamond or square that equals 2.

A: DP, this blog is better than the figure

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 namespacestd; typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#definePB Push_back#defineFi first#defineSe Second#defineMP Make_pairConst intn=550;Constll INF = 1ll<< A;Const intINF =1000000007;Const intMOD =2000000011;CharMp[n][n];intDp[n][n],n;intsolve () {intAns =0;    MEM (DP);  for(intI=1; i<=n;i++) {         for(intj=1; j<=n;j++) {            if(Mp[i][j] = ='x') {                inttmp = 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(intI=1; i<=n;i++) {         for(intj=1; j<=n;j++) {            if(Mp[i][j] = ='x') {                inttmp = 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; ElseDP[I][J] =tmp; if(Dp[i][j] >1) ans +=dp[i][j]-1; }        }    }    returnans;}intMain () { while(SCANF ("%d", &n)! =EOF) {         for(intI=1; i<=n;i++) {GetChar ();  for(intj=1; j<=n;j++) scanf ("%c",&Mp[i][j]); } printf ("%d\n", Solve ()); }    return 0;}
Code

UVA 10593 Kites DP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.