poj-3230 Travel
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<100.
Output
Sample Input
3 3
3 1 2
2 3 1
1 3 2 2 4 3
4 3 2
3 4 2 0 0
Sample Output
8
Hint
-1+4-2+4-1+4=8;
OJ-ID:
poj-3230
author:
Caution_X
date of submission:
20191019
tags:
dp
description modelling:
某人去旅行一趟,输入包含从城市i->j的花费cost[i][j]和第i天待在城市j可以得到的钱w[i][j],求m天后的最大钱数
major steps to solve it:
dp[i][j]:=第i天待在第j个成=城市得到的最大金钱
dp[i][j]=max(dp[i][j],dp[i-1][k]-cost[k][j]+w[i][j]);
AC code:
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int dp[][],w[][],cost[][];
int main()
{
//freopen("input.txt","r",stdin);
int n,m;
while(~scanf("%d%d",&n,&m)&&n&&m) {
memset(dp,-,sizeof(dp));
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",&w[i][j]);
}
}
dp[][]=;
for(int i=;i<=n;i++) dp[][i]= -cost[][i]+w[][i];
for(int i=;i<=m;i++) {
for(int j=;j<=n;j++) {
for(int k=;k<=n;k++) {
dp[i][j]=max(dp[i][j],dp[i-][k]-cost[k][j]+w[i][j]);
}
}
}
int ans=-;
for(int i=;i<=n;i++) {
ans=max(ans,dp[m][i]);
}
printf("%d\n",ans);
}
}
poj-3230 Travel的更多相关文章
- poj 3230 Travel(dp)
Description One traveler travels among cities. He has to pay for this while he can get some incomes. ...
- poj 3230(初始化。。动态规划)
Travel Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4353 Accepted: 1817 Descriptio ...
- POJ 3230 【DP】
题意: 某货旅行,在n个城市呆m天. 给出从第i个城市到第j个城市的路费,或者留在某个城市的生活费. 给出在第i天在第j个城市的收益. 可以在城市之间任意穿梭逗留没有其他特殊要求. 求收益最大是多少. ...
- POJ 3230 DP
f[i][j]=max(f[i][j],f[i-1][k]-a[k][j]+b[i][j]) i->第i天 j-–>到第j个城市 #include <cstdio> #incl ...
- {POJ}{动态规划}{题目列表}
动态规划与贪心相关: {HDU}{4739}{Zhuge Liang's Mines}{压缩DP} 题意:给定20个点坐标,求最多有多少个不相交(点也不相交)的正方形 思路:背包问题,求出所有的正方形 ...
- 15年-ICPC长春-网络赛
ID name status one word POJ 5437 Alisha’s Party 赛后AC. 优先队列,模拟.对时间t排序 POJ 5438 Ponds 赛后AC 循环链表 POJ 5 ...
- poj 3229 The Best Travel Design ( 图论+状态压缩 )
The Best Travel Design Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1359 Accepted: ...
- POJ 3229:The Best Travel Design
Description Dou Nai ), and the end of the travel route hours on traveling every day. Input There are ...
- poj 1251 Jungle Roads (最小生成树)
poj 1251 Jungle Roads (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...
- POJ 3422 Kaka's Matrix Travels
Kaka's Matrix Travels Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9567 Accepted: ...
随机推荐
- 记一次收集APP native崩溃信息
最近在学习 极客时间Android开发高手课 老师推荐了Breakpad开源库来采集native 的crash1.为什么要使用Google Breakpad? 我们在开发过程中,Android JNI ...
- 用Python查找数组中出现奇数次的那个数字
有一个数组,其中的数都是以偶数次的形式出现,只有一个数出现的次数为奇数次,要求找出这个出现次数为奇数次的数. 集合+统计 解题思路 最简单能想到的,效率不高.利用集合的特性,通过 Python 的 s ...
- 爬虫框架-selenium
selenium介绍: selenium最初是一个自动化测试工具,而爬虫中使用它主要是为了解决requests无法直接执行JavaScript代码的问题 selenium本质是通过驱动浏览器,完全模拟 ...
- SpringBoot(九)RabbitMQ安装及配置和使用,消息确认机制
Windows下RabbitMQ安装及配置地址: https://blog.csdn.net/zhm3023/article/details/82217222RabbitMQ(四)订阅模式:https ...
- E203 CSR rtl实现分析
CSR状态控制寄存器,每个hart都有自己的CSR.对于每个hart,可以配置的状态寄存器是4k.CSR寄存器的功能见:https://www.cnblogs.com/mikewolf2002/p/1 ...
- Dynamics 365 Customer Engagement中使用JavaScript和C#调用操作Action示例
微软动态CRM专家罗勇 ,回复334或者20190509可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me! Action (操作)是流程的一种,可以在工作流中调用,可以使用 ...
- this license XXXXXX has been cancelled
this license XXXXXX has been cancelled问题解决:首先修改hosts 文件 加入0.0.0.0 account.jetbrains.comhosts 目录 wind ...
- 一行代码完成 Java的 Excel 读写--easyexcel
最近我在 Github 上查找一个可以快速开发 excel 导入导出工具,偶然发现由阿里开发 easyexcel 开源项目,尝试使用后感觉这款工具挺不错的,下面分享一下我的 easyexcel 案例使 ...
- Troubleshooting ORA-01555 - Snapshot Too Old: Rollback Segment Number "String" With Name "String" Too Small (Doc ID 1580790.1)
Troubleshooting ORA-01555 - Snapshot Too Old: Rollback Segment Number "String" With Name & ...
- [日常] 解决docker拉取镜像速度慢的问题
将docker修改为国内镜像源 在/etc/docker/daemon.json文件中添加下面参数 此处使用的是中国科技大学的docker镜像源 { "registry-mirrors ...