Codeforces 225C Barcode

Source: Internet
Author: User

Test instructions: give you a matrix that contains only ' # ' and '. ', and now each column must be the same, up to a continuous y column with at least the same number of consecutive X columns.

Solution thinking: 3-D dp,dp[i][j][k] denotes column I, State J, is the K-line of State J.

Problem Solving Code:

1 //File name:225c.cpp2 //Author:darkdream3 //Created time:2015 March 09 Monday 09:49 05 Seconds4#include <climits>5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long - using namespacestd; - Charstr[1005][1005]; - intdp[1005][2][1005]; - intcw[1005]; in intBb:1005]; - intMain () { to   intN, m, x, y; +memset (dp,-1,sizeof(DP)); -scanf"%d %d%d%d",&n,&m,&x,&y); the    for(inti =1; I <= N;i + +) *   { $scanf"%s", &str[i][1]);Panax Notoginseng   } -    for(inti =1; I <= M;i + +) the   { +      for(intj =1; J <= N;j + +) A     { the       if(Str[j][i] = ='#') +Cw[i] + + ; -     } $Cb[i] = n-Cw[i]; $   } -dp[1][0][1] = cb[1]; -dp[1][1][1] = cw[1]; the    for(intI=2; I <= M;i + +) -   {Wuyi      intMXCB =-1; the       for(intj =1; J <= y; j + +) -      { Wu           if(dp[i-1][0][J]! =-1) -           { Aboutdp[i][0][j+1] = dp[i-1][0][J] +Cb[i]; $             if(J >=x) -             { -              if(MXCB = =-1) -MXCB = dp[i-1][0][j]; A              Else  +MXCB = min (mxcb,dp[i-1][0][j]); the             } -           } $      } the      intMXCW =-1;  the       for(intj =1; J <= y; j + +) the      { the           if(dp[i-1][1][J]! =-1) -           { indp[i][1][j+1] = dp[i-1][1][J] +Cw[i]; the             if(J >=x) the             { About              if(MXCW = =-1) theMXCW = dp[i-1][1][j]; the              Else  theMXCW = min (mxcw,dp[i-1][1][j]); +             } -           } the      }Bayi      //printf ("%d%d\n", MXCW,MXCB); the      if(MXCW! =-1) thedp[i][0][1] = MXCW +Cb[i]; -      if(MXCB! =-1) -dp[i][1][1] = MXCB +Cw[i]; the   } the   intAns =Int_max; the    for(inti =0; I <2; i + +) the        for(intj = x; J <= y; J + +) -       { the         if(Dp[m][i][j]! =-1) theAns =min (dp[m][i][j],ans); the       }94   /*for (int i = 1;i <= m;i + +) the   { the For (int s = 0; s <= 1; s + +) the    {98 for (int j= 1;j <= y; j + +) About printf ("%d", dp[i][s][j]); - printf ("* * *");101    }102 printf ("\ n");103   }*/104printf"%d\n", ans); the return 0;106}
View Code

Codeforces 225C Barcode

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.