zoukankan      html  css  js  c++  java
  • sicily 1563 水水的DP

    http://soj.me/show_problem.php?pid=1563

    明显的水题,几分钟敲出来;
    测试下样例,居然发现答案不一样。。
    鉴于上次乌龟棋数组开太小,数据是long的,虽然目测这题数据还行,还是改成long了。。int  我估计也行。。
     目测纠结一番,不知道哪里错了。
     输出每次 cur[][] 的变化,更加郁闷,有最大值32啊,为什么我输出26呢。。
    输出答案,更加郁闷;
    我就不信是人品技术问题。。
    再瞄~~
    26是最后一行的。。。
    WA!!我倒,要输出 ans 的,居然打成cur[][];
    AC了。。。
    大清早的拿道题清醒下。居然发生这种事情,T~T...。 

    06.#include<iostream>
    07.#include<cstring>
    08.using namespace std;
    09.long a[1001][1001],cur[502][502];
    10. 
    11.long max(long a,long b,long c)
    12.{
    13.long t = a>b?a:b;
    14.return t>c?t:c;
    15.}
    16.int main()
    17.{
    18.int col,row;
    19.cin>>row>>col;
    20.for(int i = 1 ; i <= row; i++)
    21.for(int j = 1 ; j <= col ; j++)
    22.cin>>a[i][j];
    23. 
    24.memset(cur,0,sizeof(int));
    25.for(int i=1;i<=col;i++)
    26.cur[1][i] = a[1][i];
    27. 
    28.for(int i=1;i<=row;i++)
    29.{
    30.for(int j=1;j<=col;j++)
    31.cur[i][j]=max(cur[i-1][j],cur[i-1][j-1],cur[i-1][j+1] )+a[i][j]; 
    32.//  cout << i << " i j" <<j<<" "<<cur[i][j]<<endl;
    33.}
    34. 
    35.long ans = 0 ;
    36.for(int i=1;i<=col;i++)
    37.{    if(cur[row][i]>ans)
    38.ans = cur[row][i];  // cout <<"@"<< ans<<endl;
    39.}  
    40.cout <<ans<<endl;
    41.return 0;
    42.}
  • 相关阅读:
    Python 学习笔记 11.模块(Module)
    Python 学习笔记 8.引用(Reference)
    Python 学习笔记 9.函数(Function)
    Python 学习笔记 6.List和Tuple
    Python 学习笔记 4.if 表达式
    Python 学习笔记 2.自省
    Python 学习笔记 3.简单类型
    Python 学习笔记 7.Dictionary
    Python 学习笔记 5.对象驻留
    Python 学习笔记 10.类(Class)
  • 原文地址:https://www.cnblogs.com/tinyork/p/3440958.html
Copyright © 2011-2022 走看看