UVaLive 6853 Concert Tour (DP)
题意:给定 n 个城市,m 个月,表示要在这 n 个城市连续 m 个月开演唱会,然后给定每个月在每个城市开演唱会能获得的利润,然后就是演唱会在不同城市之间调动所要的费用,
问你,怎么安排这 n 个演唱会是最优的。
析:很明显的一个DP题,并且也不难,用dp[i][j] 表示在第 i 个月,在第 j 个城市开演唱会,是最优的。那么状态转移方程也就出来了
dp[i][j] = Max(dp[i][j], dp[i-1][k]-f[k][j]+p[j][i]);
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 100;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int p[105][55];
int f[105][105];
int dp[55][105]; int main(){
int T; cin >> T;
while(T--){
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
scanf("%d", p[i]+j);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
scanf("%d", f[i]+j); memset(dp, 0, sizeof dp);
for(int i = 1; i <= n; ++i) dp[1][i] = p[i][1];
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]-f[k][j]+p[j][i]); int ans = 0;
for(int i = 1; i <= n; ++i) ans = Max(ans, dp[m][i]);
printf("%d\n", ans);
}
return 0;
}
UVaLive 6853 Concert Tour (DP)的更多相关文章
- UVALive 6853(dp)
题意:已知有n个城市,某歌手每月进行一场演唱会,共持续c个月,可连续两个月在同一个城市.城市间的路费已给出,且已知每个城市在第k(1<=k<=c)个月举办演唱会的所得利润,求最终的最大利润 ...
- POJ2677 Tour[DP 状态规定]
Tour Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4307 Accepted: 1894 Description ...
- POJ2677 Tour(DP+双调欧几里得旅行商问题)
Tour Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3929 Accepted: 1761 Description ...
- USACO Seciton 5.4 Canada Tour(dp)
因为dp(i,j)=dp(j,i),所以令i>j. dp(i,j)=max(dp(k,j))+1(0<=k<i),若此时dp(i,j)=1则让dp(i,j)=0.(因为无法到达此状态 ...
- UVALive - 6952 Cent Savings dp
题目链接: http://acm.hust.edu.cn/vjudge/problem/116998 Cent Savings Time Limit: 3000MS 问题描述 To host a re ...
- UVALive - 6529 找规律+dp
题目链接: http://acm.hust.edu.cn/vjudge/problem/47664 Eleven Time Limit: 5000MS 问题描述 In this problem, we ...
- UVaLive 6801 Sequence (计数DP)
题意:给定一个序列,有 n 个数,只有01,然后你进行k次操作,把所有的1变成0,求有多种方法. 析:DP是很明显的,dp[i][j] 表示进行第 i 次操作,剩下 j 个1,然后操作就两种,把1变成 ...
- UVaLive 6697 Homework Evaluation (DP)
题意:给出一个长字符串,再给一个短字符串,进行匹配,如果第i个恰好匹配,则 +8,:如果不匹配,可以给长或短字符串添加-,先后匹配,这样-3, 连续的长字符串添加-,需要减去一个4:也可不给添加-,则 ...
- UVaLive 7374 Racing Gems (DP,LIS)
题意:以辆赛车可以从x轴上任意点出发,他的水平速度允许他向每向上移动v个单位,就能向左或向右移动v/r个单位(也就是它的辐射范围是个等腰三角形) 现在赛车从x轴出发,问它在到达终点前能吃到的最多钻石. ...
随机推荐
- pppoe server 搭建
Ubuntu 上搭建 pppoe server sudo apt-get install pppoe $ cat /etc/ppp/pppoe-server-options # PPP options ...
- hdu 3932 Groundhog Build Home
Groundhog Build Home Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- Java多线程学习(吐血超详细总结)转自博主林炳文Evankaka
文章由林炳文Evankaka原创.转载自http://blog.csdn.net/evankaka 写在前面的话:此文只能说是Java多线程的一个入门,其实Java里头线程完全可以写一本书了,但是如果 ...
- 操作系统 资源管理 zookeeper yarn 进程管理 分布式 yarn诞生背景
zookeeper 信息保管员 YARN 简介 https://www.ibm.com/developerworks/cn/data/library/bd-yarn-intro/index.html
- 1022. Fib数列
https://acm.sjtu.edu.cn/OnlineJudge/problem/1022 Description 定义Fib数列:1,1,2,3,5,8,13,…1,1,2,3,5,8,13, ...
- Spring boot框架项目,使用maven命令将配置文件打包到jar包外,项目运行读取jar外配置文件
1.1 在eclipse中配置maven命令 Mvn -e clean package -Ptest -DskipTests=true 1.1.1 执行命令之后得到jar 1.2 ...
- SCOI2017 游记(AFO)
SCOI2017 游记(AFO) Day 0 上午模拟考,又tm用暴力a了一道题,心情舒畅.(要是省选也这样该有多好,2333) 晚上又去吃了什么不知名的东西,自己都忘了,总之好像很好吃的样子. Da ...
- Gym - 100187J J - Deck Shuffling —— dfs
题目链接:http://codeforces.com/gym/100187/problem/J 题目链接:问通过洗牌器,能否将编号为x的牌子转移到第一个位置? 根据 洗牌器,我们可以知道原本在第i位置 ...
- MySQL学习笔记(一)——数据库基础
自己上大学时也学习过数据库,做开发时也用到过,但是做界面开发对于数据库的使用相对来说是比较简单的,大学时系统学习的数据库也还给老师了,在测试工作中也只是用到了一些基础sql,增删改查这一类的,但是自己 ...
- python berkeley DB操作——打开btree索引文件中的database
打开BDB中某个索引中的数据库代码: from bsddb3 import db import bsddb3 as bsddb print db.DB_VERSION_STRING mydb = db ...