cf 154.div2 D. Table with Letters - 2

简介:

D. Table with Letters - 2

 

      今天的比赛题比较奸诈,居然是文件读入的,让A题耽误了很多时间。

   

      这题是dp的一个经典类型,o((n*m)^2)的算法非常好写,但是必然TLE。因为其要求四角均相等,不妨以此为条件进行判断,即可缩为o(n^2*m)算法

 

    /*
    author:jxy
    lang:C/C++
    university:China,Xidian University
    **If you need to reprint,please indicate the source**
    */
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <queue>
    #define INF 1E9
    using namespace std;
    int sum[402][402];
    char a[402][402];
    int main()
    {
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        int m,n,K,i,j,t;
        scanf("%d%d%d",&n,&m,&K);
        memset(sum,0,sizeof(sum));
        for(i=1;i<=n;i++)
        {
            getchar();
          for(j=1;j<=m;j++)
          {
              a[i][j]=getchar();
              sum[i][j]=0-sum[i-1][j-1]+sum[i-1][j]+sum[i][j-1];
              if(a[i][j]=='a')sum[i][j]++;
          }
        }
        long long ans=0;
        int now[257],k,p;
        for(i=1;i<=n;i++)
          for(j=i+1;j<=n;j++)
          {
              memset(now,0,sizeof(now));
              for(k=1,p=1;k<=m;k++)
              {
                  if(a[i][k]!=a[j][k])continue;
                  now[a[i][k]]--;
                 // if(p==1)p=k;
                  //cout<<now[a[i][k]]<<endl;
                  while(p<=m&&sum[j][p]+sum[i-1][k-1]-sum[i-1][p]-sum[j][k-1]<=K)
                  {
                      if(a[i][p]==a[j][p])now[a[i][p]]++;
                      p++;
                  }
                  if(now[a[i][k]]>0)ans+=now[a[i][k]];
                  //cout<<now[a[i][k]]<<" --------"<<endl;
              }
          }
        cout<<ans<<endl;
    }


 

目录
相关文章
|
7月前
CF443A Anton and Letters(去重set函数)
CF443A Anton and Letters(去重set函数)
26 0
|
16天前
|
索引 Python
row[i] = col[j] = TrueIndexError: list assignment index out of range
row[i] = col[j] = TrueIndexError: list assignment index out of range
|
SQL 关系型数据库 MySQL
MySQL数据库报错 > 1366 - Incorrect string value: ‘\xE6\xB1\x9F\xE6\x96\x87‘ for column ‘Teacher‘ at row 1
MySQL数据库报错 > 1366 - Incorrect string value: ‘\xE6\xB1\x9F\xE6\x96\x87‘ for column ‘Teacher‘ at row 1
206 0
MySQL数据库报错 > 1366 - Incorrect string value: ‘\xE6\xB1\x9F\xE6\x96\x87‘ for column ‘Teacher‘ at row 1
ng-repeat part1 - how UI is rendered from {{name}} to actual value
ng-repeat part1 - how UI is rendered from {{name}} to actual value
ng-repeat part1 - how UI is rendered from {{name}} to actual value
when click one item in table Select at least one column to perform the search
when click one item in table Select at least one column to perform the search
when click one item in table Select at least one column to perform the search
ng-repeat part2 - How &lt;li ng-repeat=&quot;nameF in Ionames&quot;&gt;{{nameF}}&lt;/li&gt; is parsed
ng-repeat part2 - How &lt;li ng-repeat=&quot;nameF in Ionames&quot;&gt;{{nameF}}&lt;/li&gt; is parsed
ng-repeat part2 - How &lt;li ng-repeat=&quot;nameF in Ionames&quot;&gt;{{nameF}}&lt;/li&gt; is parsed
OPA 6 - module(&quot;Create Button Test&quot;);
Created by Wang, Jerry, last modified on Nov 08, 2015
OPA 6 - module(&quot;Create Button Test&quot;);
OPA 13 - ok(oButton,&quot;find the Create button&quot;);
Created by Wang, Jerry, last modified on Nov 08, 2015
101 0
OPA 13 - ok(oButton,&quot;find the Create button&quot;);
|
Web App开发 关系型数据库 Java
Data truncation: Data too long for column 'xxx' at row 1
版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/78870542 ...
2060 0
|
Web App开发 Java 关系型数据库
Data truncation: Data too long for column &#39;xxx&#39; at row 1
Data truncation: Data too long for column 'xxx' at row 1 完整的错误内容可能是下面这样的: p.p1 {margin: 0.0px 0.0px 0.
2075 0