\(problem\)

这题 灰常的相似

然后内存可能过大 开个滚动数组

因为数塔问题总是 只需要上面一行的两个状态(这题就是数塔问题)

下面的代码与原题不符。(原题要输出路径)想抄的可以走了

输出路径只需要数组记录一下就好了。

#ifdef Dubug

#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long LL ;
inline LL In() {
LL res(0),f(1);
register char c ;
while(isspace(c=getchar())) ;
c == '-'? f = -1 , c = getchar() : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(c=getchar())) ;
return res * f ;
}
int n , m , k ;
const int N = 900 + 5 ;
const int Arr = 100 + 5 ;
short num[Arr][Arr] ;
bool dp[Arr][Arr][N] ;
bool b[N] ;
char s[Arr] ;
inline void get(int x) {
for(register int i=1; i<=N/x; i++) b[i*x] = true ;
return ;
}
inline void Ot() {
memset(dp,0,sizeof(dp)) ;
for(register int j=1; j<=m; j++) dp[n][j][num[n][j]] = true ;
for(register int i=n-1; i>=1; i--)
for(register int j=1; j<=m; j++)
for(register int q=0; q<N; q++) {
if(dp[(i+1)][j-1][q]) dp[i][j][q+num[i][j]] = true ;
if(dp[(i+1)][j+1][q]) dp[i][j][q+num[i][j]] = true ;
}
int Max = -1 ;
for(register int i=1; i<=m; i++)
for(register int q=0; q<N; q++) if(dp[1][i][q] and b[q]) Max = max (Max,q) ;
cout << Max << endl ;
}
signed main() {
#ifdef Online_Judge
freopen("test.in","r",stdin) ;
freopen("testdata.out","w",stdout) ;
#endif
n = In() , m = In() , k = In() ;
for(register int i=1; i<=n; i++) {
scanf("%s",s+1);
for(register int j=1; j<=m; j++) num[i][j] = s[j]&15 ;
}
get(k+1) ;
return Ot() , 0 ;
}
#ifdef Dubug

#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long LL ;
inline LL In() {
LL res(0),f(1);
register char c ;
while(isspace(c=getchar())) ;
c == '-'? f = -1 , c = getchar() : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(c=getchar())) ;
return res * f ;
}
int n , m , k ;
const int N = 900 + 5 ;
const int Arr = 100 + 5 ;
short num[Arr][Arr] ;
bool dp[2][Arr][N] ;
bool b[N] ;
char s[Arr] ;
inline void get(int x) {
memset(b,false,sizeof(b)) ;
for(register int i=1; i<=N/x; i++) b[i*x] = true ;
return ;
}
inline void Ot() {
memset(dp,0,sizeof(dp)) ;
for(register int j=1; j<=m; j++) dp[n&1][j][num[n][j]] = true ;
for(register int i=n-1; i>=1; i--)
for(register int j=1; j<=m; j++)
for(register int q=0; q<N; q++) {
if(dp[(i+1)&1][j-1][q]) dp[i&1][j][q+num[i][j]] = true ;
if(dp[(i+1)&1][j+1][q]) dp[i&1][j][q+num[i][j]] = true ;
}
int Max = -1 ;
for(register int j=1; j<=m; j++)
for(register int q=0; q<N; q++) if(dp[1][j][q] and b[q]) Max = max (Max,q) ;
cout << Max << endl ;
}
signed main() {
#ifdef Online_Judge
freopen("test.in","r",stdin) ;
freopen("testdata.out","w",stdout) ;
#endif
n = In() , m = In() , k = In() ;
for(register int i=1; i<=n; i++) {
scanf("%s",s+1);
for(register int j=1; j<=m; j++) num[i][j] = s[j]&15 ;
}
get(k+1) ;
return Ot() , 0 ;
}

随机推荐

  1. 热词解析(9) — hangry

    今天给大家介绍一个非常有趣.又超级实用的词!!中文叫"饿极而怒",英文叫... 不知道你有没有这样的经历,当你饿着肚子等着你妈做饭,结果你妈却在麻将桌上不下来,你就越来越饿,越饿越 ...

  2. airfoil polar data during post stall stages (high AOA)

    airfoil polar data during post stall stages (high AOA) Table of Contents 1. airfoil polar during pos ...

  3. 洛谷 2824 [HEOI2016/TJOI2016]排序

    [题意概述] 对一个1到n的排列做m次区间排序,最后询问位置q上面的数. [题解] 区间排序的效率是nlogn,所以暴力做的话效率是mnlogn,显然达不到要求. 我们考虑二分答案.如果某个位置的数比 ...

  4. [bzoj1833][ZJOI2010][count] (数位dp)

    Description 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. Input 输入文件中仅包含一行两个整数a.b,含义如上所述. Output 输出文 ...

  5. 前端面试题总结一(js变量和函数声明提前相关)

    好久没有更新博客了,^_^写写博客吧!下面是我总结的一些面试题,希望对大家有所帮助 (1)题目如下: alert(a)  var a=1  function a(){    alert(a) } 好多 ...

  6. openstack windows2012r2 glance镜像制作

    镜像实现: 密码注入 修改密码 根分区扩展 1.下载windows iso镜像 下载地址:http://imsdn.com/MSDN-1.html 例如:cn_windows_server_2012_ ...

  7. [USACO06JAN]牛的舞会The Cow Prom Tarjan

    题目描述 The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their ...

  8. SQL Server死锁总结 [转]

    1. 死锁原理 根据操作系统中的定义:死锁是指在一组进程中的各个进程均占有不会释放的资源,但因互相申请被其他进程所站用不会释放的资源而处于的一种永久等待状态. 死锁的四个必要条件:互斥条件(Mutua ...

  9. System.out.print()思考?

            System.out.print()思考       问题?                 System.out.pritln();  中是包名.类名.方法名吗? 解释: Syste ...

  10. Ubuntu 16.04安装GIMP替代PS

    GIMP虽然不能完全替代PS,但是也能弥补一下. 系统默认源中已经包含了GIMP,不需要使用PPA这些. 安装: sudo apt-get install gimp 启动: 通过Dash搜索GIMP即 ...