题意:给定 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]);

代码如下:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <stack>
  16. #define freopenr freopen("in.txt", "r", stdin)
  17. #define freopenw freopen("out.txt", "w", stdout)
  18. using namespace std;
  19. typedef long long LL;
  20. typedef pair<int, int> P;
  21. const int INF = 0x3f3f3f3f;
  22. const double inf = 0x3f3f3f3f3f3f;
  23. const LL LNF = 0x3f3f3f3f3f3f;
  24. const double PI = acos(-1.0);
  25. const double eps = 1e-8;
  26. const int maxn = 1e3 + 100;
  27. const int mod = 1e9 + 7;
  28. const int dr[] = {-1, 0, 1, 0};
  29. const int dc[] = {0, 1, 0, -1};
  30. const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  31. int n, m;
  32. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  33. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  34. inline int Min(int a, int b){ return a < b ? a : b; }
  35. inline int Max(int a, int b){ return a > b ? a : b; }
  36. inline LL Min(LL a, LL b){ return a < b ? a : b; }
  37. inline LL Max(LL a, LL b){ return a > b ? a : b; }
  38. inline bool is_in(int r, int c){
  39. return r >= 0 && r < n && c >= 0 && c < m;
  40. }
  41. int p[105][55];
  42. int f[105][105];
  43. int dp[55][105];
  44.  
  45. int main(){
  46. int T; cin >> T;
  47. while(T--){
  48. scanf("%d %d", &n, &m);
  49. for(int i = 1; i <= n; ++i)
  50. for(int j = 1; j <= m; ++j)
  51. scanf("%d", p[i]+j);
  52. for(int i = 1; i <= n; ++i)
  53. for(int j = 1; j <= n; ++j)
  54. scanf("%d", f[i]+j);
  55.  
  56. memset(dp, 0, sizeof dp);
  57. for(int i = 1; i <= n; ++i) dp[1][i] = p[i][1];
  58. for(int i = 2; i <= m; ++i)
  59. for(int j = 1; j <= n; ++j)
  60. for(int k = 1; k <= n; ++k)
  61. dp[i][j] = Max(dp[i][j], dp[i-1][k]-f[k][j]+p[j][i]);
  62.  
  63. int ans = 0;
  64. for(int i = 1; i <= n; ++i) ans = Max(ans, dp[m][i]);
  65. printf("%d\n", ans);
  66. }
  67. return 0;
  68. }

  

UVaLive 6853 Concert Tour (DP)的更多相关文章

  1. UVALive 6853(dp)

    题意:已知有n个城市,某歌手每月进行一场演唱会,共持续c个月,可连续两个月在同一个城市.城市间的路费已给出,且已知每个城市在第k(1<=k<=c)个月举办演唱会的所得利润,求最终的最大利润 ...

  2. POJ2677 Tour[DP 状态规定]

    Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4307   Accepted: 1894 Description ...

  3. POJ2677 Tour(DP+双调欧几里得旅行商问题)

    Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3929   Accepted: 1761 Description ...

  4. 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.(因为无法到达此状态 ...

  5. UVALive - 6952 Cent Savings dp

    题目链接: http://acm.hust.edu.cn/vjudge/problem/116998 Cent Savings Time Limit: 3000MS 问题描述 To host a re ...

  6. UVALive - 6529 找规律+dp

    题目链接: http://acm.hust.edu.cn/vjudge/problem/47664 Eleven Time Limit: 5000MS 问题描述 In this problem, we ...

  7. UVaLive 6801 Sequence (计数DP)

    题意:给定一个序列,有 n 个数,只有01,然后你进行k次操作,把所有的1变成0,求有多种方法. 析:DP是很明显的,dp[i][j] 表示进行第 i 次操作,剩下 j 个1,然后操作就两种,把1变成 ...

  8. UVaLive 6697 Homework Evaluation (DP)

    题意:给出一个长字符串,再给一个短字符串,进行匹配,如果第i个恰好匹配,则 +8,:如果不匹配,可以给长或短字符串添加-,先后匹配,这样-3, 连续的长字符串添加-,需要减去一个4:也可不给添加-,则 ...

  9. UVaLive 7374 Racing Gems (DP,LIS)

    题意:以辆赛车可以从x轴上任意点出发,他的水平速度允许他向每向上移动v个单位,就能向左或向右移动v/r个单位(也就是它的辐射范围是个等腰三角形) 现在赛车从x轴出发,问它在到达终点前能吃到的最多钻石. ...

随机推荐

  1. canvas 星空插件

    (function(a){ a.fn.starBg=function(p){ var p=p||{}; var w_w=p&&p.window_width?p.window_width ...

  2. IMDB-WIKI - 具有年龄和性别标签的500k +脸部图像

    Rasmus Rothe, Radu Timofte, Luc Van Gool DEX:从单一形象深刻地看待年龄 观看 人物研讨会国际计算机视觉大会(ICCV),2015*获胜LAP面对年龄估计的挑 ...

  3. 您的安全性偏好设置仅允许安装来自 App Store 和被认可的开发者的应用

    您的安全性偏好设置仅允许安装来自 App Store 和被认可的开发者的应用. 安装macOS Sierra后,会发现系统偏好设置的“安全与隐私”中默认已经去除了允许“任何来源”App的选项,无法运行 ...

  4. ORACLE 36进制和10进制,互相转换函数

    第一部分 --36转10进制 create or replace function f_36to10 (str varchar) return int  is returnValue int;   s ...

  5. listview 下拉刷新

    http://blog.csdn.net/lancees/article/details/7776853

  6. Vue入门(一) 环境配置

    Node.js 安装,https://nodejs.org/en/  默认安装就可以 安装好后测试版本,cmd  键入命令 1.node -v 2.npm -v 安装,淘宝 NPM         n ...

  7. Storage Types and Storage Policies

    https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-hdfs/ArchivalStorage.html Introduc ...

  8. 浏览器访问配置完成的ftp服务器

    在浏览器的地址栏输入: ftp://testuser:testuser@192.168.10.4 testuser 是ftp的用户名和密码: 192.168.10.4 是ftp服务器的IP地址. 亲测 ...

  9. a little riak book

    a little riak book 的无聊总结 <pre name="code" class="python">#!/bin/bash # Ria ...

  10. 大数据之环境准备系列 ——第二篇 新装VMware 虚拟机 网络配置(NAT模式)

    新安装虚拟机,需要配置网络环境,才可以使用ssh客户端(如xshell)远程登录 和 虚拟机访问Internet. 一. WMware 软件配置 WMware版本号:11.0.0 build-2305 ...