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轴出发,问它在到达终点前能吃到的最多钻石. ...
随机推荐
- canvas 星空插件
(function(a){ a.fn.starBg=function(p){ var p=p||{}; var w_w=p&&p.window_width?p.window_width ...
- IMDB-WIKI - 具有年龄和性别标签的500k +脸部图像
Rasmus Rothe, Radu Timofte, Luc Van Gool DEX:从单一形象深刻地看待年龄 观看 人物研讨会国际计算机视觉大会(ICCV),2015*获胜LAP面对年龄估计的挑 ...
- 您的安全性偏好设置仅允许安装来自 App Store 和被认可的开发者的应用
您的安全性偏好设置仅允许安装来自 App Store 和被认可的开发者的应用. 安装macOS Sierra后,会发现系统偏好设置的“安全与隐私”中默认已经去除了允许“任何来源”App的选项,无法运行 ...
- ORACLE 36进制和10进制,互相转换函数
第一部分 --36转10进制 create or replace function f_36to10 (str varchar) return int is returnValue int; s ...
- listview 下拉刷新
http://blog.csdn.net/lancees/article/details/7776853
- Vue入门(一) 环境配置
Node.js 安装,https://nodejs.org/en/ 默认安装就可以 安装好后测试版本,cmd 键入命令 1.node -v 2.npm -v 安装,淘宝 NPM n ...
- Storage Types and Storage Policies
https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-hdfs/ArchivalStorage.html Introduc ...
- 浏览器访问配置完成的ftp服务器
在浏览器的地址栏输入: ftp://testuser:testuser@192.168.10.4 testuser 是ftp的用户名和密码: 192.168.10.4 是ftp服务器的IP地址. 亲测 ...
- a little riak book
a little riak book 的无聊总结 <pre name="code" class="python">#!/bin/bash # Ria ...
- 大数据之环境准备系列 ——第二篇 新装VMware 虚拟机 网络配置(NAT模式)
新安装虚拟机,需要配置网络环境,才可以使用ssh客户端(如xshell)远程登录 和 虚拟机访问Internet. 一. WMware 软件配置 WMware版本号:11.0.0 build-2305 ...