栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3827 Facer is learning to...

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3827 Facer is learning to...

#include <cstdio>#include <algorithm>#include <cstring>#include <iostream>using namespace std;typedef long long LL;const int MAXN = 110;const int MAXM = 1010;const int INF = 0x3fff3fff;int dp[MAXM];int mat[MAXN][MAXM];bool money[MAXN][MAXM];int n, m, k;void dfs(int from, int ti, int tj, int spd, int sum) {    if(ti < 1) ti = 1;    if(ti > n) ti = n;    if(ti == 1 && from != tj) {        if(dp[tj] < sum) dp[tj] = sum;        return ;    }    if(tj - from == k || tj == m) return ;    if(money[ti][tj]) sum += mat[ti][tj];    else if(ti != 1) spd += mat[ti][tj];    dfs(from, ti + spd - 1, tj + 1, spd - 1, sum);    dfs(from, ti + spd    , tj + 1, spd    , sum);    dfs(from, ti + spd + 1, tj + 1, spd + 1, sum);}void solve() {    dp[1] = 0;    for(int i = 2; i <= m; ++i) dp[i] = -INF;    for(int i = 1; i < m; ++i) {        if(dp[i] == -INF) continue;        dfs(i, 1, i, 0, dp[i]);    }    if(money[1][m]) dp[m] += mat[1][m];    printf("%dn", dp[m]);}char lastch = ' ';inline char readchar() {    while(lastch != 'v' && lastch != '$')        lastch = getchar();    return lastch;}inline int readint() {    int g = 0, l;    while(!isdigit(lastch) && lastch != '-') lastch = getchar();    if(lastch == '-') {        l = -1;        lastch = getchar();    }    else l = 1;    while(isdigit(lastch)) {        g = g * 10 + lastch - '0';        lastch = getchar();    }    return g * l;}int main() {    while(true) {        n = readint(); m = readint(); k = readint();        if(n + m + k == 0) break;        char c;        for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) {     c = readchar();     mat[i][j] = readint();     money[i][j] = (c == '$'); }        }        solve();    }}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373651.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号