POJ 3230 Travel(朴素DP)
来源:互联网 发布:中国人民大学 知乎 编辑:程序博客网 时间:2024/05/17 18:19
题目地址:http://poj.org/problem?id=3230
思路:看清题就行,没钱的时候还能欠债
AC代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <cstring>#include <climits>#include <cmath>#include <cctype>const int inf = 0x3f3f3f3f;//1061109567typedef long long LL;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;int cost[110][110];int dp[110][110];int income[110][110];int main(){ int n,m; while(scanf("%d%d",&n,&m) != EOF) { if(n + m == 0) break; for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { scanf("%d",&cost[i][j]); } } for(int i=1; i<=m; i++) { for(int j=1; j<=n; j++) { scanf("%d",&income[i][j]); } } memset(dp,-inf,sizeof(dp)); int max1 = -inf; for(int i=1; i<=n; i++) { dp[1][i] = income[1][i] - cost[1][i]; if(dp[1][i] > max1) max1 = dp[1][i]; } for(int i=2; i<=m; i++) { for(int j=1; j<=n; j++) { for(int k=1; k<=n; k++) { dp[i][j] = max(dp[i][j], dp[i-1][k] - cost[k][j] + income[i][j]); } if(dp[i][j] > max1) { max1 = dp[i][j]; } } } printf("%d\n",max1); }}
0 0
- POJ 3230 Travel(朴素DP)
- poj 3230 Travel 简单dp
- [水+dp] poj 3230 Travel
- 水水的DP Travel POJ 3230
- POJ 3230 Travel 动态规划Dp
- POJ 3661 Running(朴素DP)
- POJ 3230 Travel
- poj 3230 Travel
- ACM篇:POJ 3230 -- Travel
- DP : Travel
- HDU 4284--Travel(状压dp+TSP)
- Hdu 4571 Travel in time(dp)
- HDU 4284 Travel(状压dp)
- UVALive 6904Travel Card(dp)
- 区间DP -- 石子合并(朴素DP)
- POJ 3625(朴素prim)
- POJ3230 Travel (DP)
- dp Happy Travel
- 【杭电-oj】-2044-一只小蜜蜂...(递推)
- 管理Hbase表中的记录
- Spring之IOC(学习笔记)
- IOS TextField设置大全
- (android开发http拦截)fiddler2抓包工具
- POJ 3230 Travel(朴素DP)
- Android 高仿微信通讯录
- HDU 5687 Problem C (2016年百度之星资格赛C题)
- Markdown的使用
- shared server使用与配置
- 构造MaxTree O(n)方法
- 《hadoop进阶》PeopleRank从社交关系中挖掘价值用户
- jQuery事件鼠标事件
- 线程安全问题