poj 3230 Travel(dp)
Description
One traveler travels among cities. He has to pay for this while he can get some incomes. Now there are n cities, and the traveler has m days for traveling. Everyday he may go to another city or stay there and pay some money. When he come to a city ,he can get some money. Even when he stays in the city, he can also get the next day's income. All the incomes may change everyday. The traveler always starts from city 1. Now is your turn to find the best way for traveling to maximize the total income.
Input
There are multiple cases. The first line of one case is two positive integers, n and m .n is the number of cities, and m is the number of traveling days. There follows n lines, one line n integers. The j integer in the i line is the expense of traveling from city i to city j. If i equals to j it means the expense of staying in the city. After an empty line there are m lines, one line has n integers. The j integer in the i line means the income from city j in the i day. The input is finished with two zeros. n,m<.
Output
You must print one line for each case. It is the max income.
Sample Input
Sample Output
Hint
In the Sample, the traveler can first go to city , then city , and finish his travel in city . The total income is: -+-+-+=;
dp[i][j] 代表第i天在j城市 最多赚了多少钱。
起点在1,所以dp[0][1]=0
然后三重循环dp就好了·
注意赚的钱有可能是负的~
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
using namespace std;
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 106
#define inf 1<<26
int n,m;
int cost[N][N];
int _get[N][N];
int dp[N][N];
int main()
{
while(scanf("%d%d",&n,&m)==){
if(n== && m==){
break;
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
scanf("%d",&cost[i][j]);
}
}
for(int i=;i<=m;i++){
for(int j=;j<=n;j++){
scanf("%d",&_get[i][j]);
}
}
for(int i=;i<=m;i++){
for(int j=;j<=n;j++){
dp[i][j]=-inf;
}
}
dp[][]=;//第0天,从城市1开始,值为0
for(int i=;i<=m;i++){
for(int j=;j<=n;j++){
for(int k=;k<=n;k++){
if(_get[j][k]<)continue;
dp[i][k]=max(dp[i][k],dp[i-][j]-cost[j][k]+_get[i][k]);
}
}
} int maxxx=-inf;
for(int i=;i<=n;i++){
maxxx=max(maxxx,dp[m][i]);
}
printf("%d\n",maxxx);
}
return ;
}
poj 3230 Travel(dp)的更多相关文章
- POJ 3034 Whac-a-Mole(DP)
题目链接 题意 : 在一个二维直角坐标系中,有n×n个洞,每个洞的坐标为(x,y), 0 ≤ x, y < n,给你一把锤子可以打到地鼠,最开始的时候,你可以把锤子放在任何地方,如果你上一秒在( ...
- poj 2229 Sumsets(dp)
Sumsets Time Limit : 4000/2000ms (Java/Other) Memory Limit : 400000/200000K (Java/Other) Total Sub ...
- poj -2229 Sumsets (dp)
http://poj.org/problem?id=2229 题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数.问你不同方案数之和是多少? n很大,所以输出后9位即可. dp[i] 表示组 ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- POJ题目分类(转)
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- POJ 1847 Tram (最短路径)
POJ 1847 Tram (最短路径) Description Tram network in Zagreb consists of a number of intersections and ra ...
- POJ 2431 Expedition(探险)
POJ 2431 Expedition(探险) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] A group of co ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
随机推荐
- windows平台vhd磁盘文件挂载
在windows平台下挂载vhd磁盘文件类似于挂载iso等文件; 使用VHDMount工具挂载VHD文件 启动Hyper-V里的外部VHD文件有点困难.如果在备份驱动上有个VHD文件,并需要从其虚拟机 ...
- MySQL无法重启问题解决Warning: World-writable config file ‘/etc/my.cnf’ is ignored
MySQL无法重启问题解决Warning: World-writable config file ‘/etc/my.cnf’ is ignored
- [置顶] 教你如何搭建RobotFramework环境
看到这篇文章的朋友,相信已经知道RobotFramework是干什么的了,我这里就不再赘述了. 搭建步骤: 1. 下载安装Python,下载地址http://www.python.org/getit/ ...
- Python的字符串与数字
Python3.0通过“input”实现读取控制台的输入与用户实现交互.值得注意的是input接受的所有数据都是字符串,即使输入的是数字,依然会被当作字符串来处理.这就会出现一些问题,所以需要进行类型 ...
- CentOS6.5下使用NetHogs监控进程网络使用情况
Nethogs 是一个终端下的网络流量监控工具,它的特别之处在于能够显示每一个进程的带宽占用情况,这样能够更直观获取网络使用情况.它支持 IPv4 和 IPv6 协议.支持本地网卡及 PPP 链接. ...
- 转:C#: static关键字的作用
tatic意思是静态,可以修饰类.字段.属性.方法 标记为static的就不用创建实例对象调用了,可以通过类名直接点出来 static三种用法: 1.用于变量前,表示每次重新使用该变量所在方法.类或自 ...
- ASP.NET,Razor语句中@符号的意义
比较下面两段代码的区别: <td> @if (item.ModifyTime.HasValue) { @item.ModifyTime.GetValueOrDefault().ToStri ...
- Linq to DataSet 和 DataSet使用方法学习
简单入门: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sy ...
- XML新手入门 创建构造良好的XML(1)
XML新手入门 创建构造良好的XML(1) 2009-03-19 09:24 Kay Whatley IBM Developerworks 我要评论(0) 字号:T | T 本文描述了构建良好的XML ...
- 简单的Mvp设计
任务:从网络上获取数据,然后显示在MainActivity的ListView上 一.载入需要用的框架 1.Mvp框架 compile 'com.hannesdorfmann.mosby:mvp:2.0 ...