zoukankan      html  css  js  c++  java
  • HDU 2571 命运

    命运

    Time Limit: 1000ms
    Memory Limit: 32768KB
    This problem will be judged on HDU. Original ID: 2571
    64-bit integer IO format: %I64d      Java class name: Main
     
    穿过幽谷意味着离大魔王lemon已经无限接近了!
    可谁能想到,yifenfei在斩杀了一些虾兵蟹将后,却再次面临命运大迷宫的考验,这是魔王lemon设下的又一个机关。要知道,不论何人,若在迷宫中被困1小时以上,则必死无疑!
    可怜的yifenfei为了去救MM,义无返顾地跳进了迷宫。让我们一起帮帮执着的他吧!
    命运大迷宫可以看成是一个两维的方格阵列,如下图所示:
     
    yifenfei一开始在左上角,目的当然是到达右下角的大魔王所在地。迷宫的每一个格子都受到幸运女神眷恋或者痛苦魔王的诅咒,所以每个格子都对应一个值,走到那里便自动得到了对应的值。
    现在规定yifenfei只能向右或者向下走,向下一次只能走一格。但是如果向右走,则每次可以走一格或者走到该行的列数是当前所在列数倍数的格子,即:如果当前格子是(x,y),下一步可以是(x+1,y),(x,y+1)或者(x,y*k) 其中k>1。 
    为了能够最大把握的消灭魔王lemon,yifenfei希望能够在这个命运大迷宫中得到最大的幸运值。

     

    Input

    输入数据首先是一个整数C,表示测试数据的组数。
    每组测试数据的第一行是两个整数n,m,分别表示行数和列数(1<=n<=20,10<=m<=1000);
    接着是n行数据,每行包含m个整数,表示n行m列的格子对应的幸运值K ( |k|<100 )。
     

    Output

    请对应每组测试数据输出一个整数,表示yifenfei可以得到的最大幸运值。
     

    Sample Input

    1
    3 8
    9 10 10 10 10 -10 10 10
    10 -11 -1 0 2 11 10 -20
    -11 -11 10 11 2 10 -10 -10

    Sample Output

    52

    Source

     
    解题:简单dp。。。
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <climits>
     7 #include <vector>
     8 #include <queue>
     9 #include <cstdlib>
    10 #include <string>
    11 #include <set>
    12 #include <stack>
    13 #define LL long long
    14 #define pii pair<int,int>
    15 #define INF 0x3f3f3f3f
    16 using namespace std;
    17 int mp[22][1010],dp[22][1010],n,m;
    18 int main() {
    19     int t;
    20     scanf("%d",&t);
    21     while(t--) {
    22         scanf("%d %d",&n,&m);
    23         for(int i = 0; i <= n; i++) dp[i][0] = -INF;
    24         for(int i = 0; i <= m; i++) dp[0][i] = -INF;
    25         for(int i = 1; i <= n; i++) {
    26             for(int j = 1; j <= m; j++)
    27                 scanf("%d",mp[i]+j);
    28         }
    29         for(int i = 1; i <= n; i++) {
    30             for(int j = 1; j <= m; j++) {
    31                 int maxV = -INF;
    32                 if(i == 1 && j == 1){
    33                     dp[i][j] = mp[i][j];
    34                     continue;
    35                 }
    36                 for(int k = 1; k < j; k++)
    37                     if(k == j-1 || j%k == 0) maxV = max(maxV,dp[i][k]);
    38                 dp[i][j] = mp[i][j] + max(maxV,dp[i-1][j]);
    39             }
    40         }
    41         printf("%d
    ",dp[n][m]);
    42     }
    43     return 0;
    44 }
    View Code
  • 相关阅读:
    一行代码更改博客园皮肤
    fatal: refusing to merge unrelated histories
    使用 netcat 传输大文件
    linux 命令后台运行
    .net core 使用 Nlog 配置文件
    .net core 使用 Nlog 集成 exceptionless 配置文件
    Mysql不同字符串格式的连表查询
    Mongodb between 时间范围
    VS Code 使用 Debugger for Chrome 调试vue
    css权重说明
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4003148.html
Copyright © 2011-2022 走看看