pid=4175">HDU 4175

题意:有C座楼,每座楼有T个教室。一个人须要訪问C个教室。每座楼仅仅能訪问一个教室。

訪问教室须要消耗能量,从x点走到y点须要消耗abs(x-y)的能量,最后要走到目的点L,问最后走到目的点L须要消耗的最少能量。

思路:读清题意,用getchar()的方式去读。。

此外英文阅读水平比較拙计,亟待提升,以后不能再直接用有道翻译来做题了。

直接暴力枚举。用dp[i][j]表示class = i , classroom = j的所需最小能量。

dp[i][j] = dp[i-1][k] + abs(e[i-1][k].pos - e[i][j].pos) + e[i][j].cost;

直接看代码吧:)

code:

/*
* @author Novicer
* language : C++/C
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
#define inf 20000000
using namespace std;
const double eps(1e-8);
typedef long long lint; struct cl{
int pos;
int cost;
};
cl e[30][1005];
int dp[30][1005];//dp[i][j]表示class = i , classroom = j的所需最小能量 int main(){
// freopen("input.txt","r",stdin);
int kase;
cin >> kase;
while(kase--){
// memset(e,0,sizeof(e));
memset(dp,0,sizeof(dp));
int c,t,l;
cin >> c >> t >> l;
for(int i = 1 ; i <= c ; i++){
for(int j = 1 ; j <= t ; j++){
scanf("%d%d",&e[i][j].pos,&e[i][j].cost);
}
}
for(int i = 1 ; i <= c ; i++){
for(int j = 1 ; j <= t ; j++){
int tmp = inf;
for(int k = 1 ; k <= t ; k++){
dp[i][j] = dp[i-1][k] + abs(e[i-1][k].pos - e[i][j].pos) + e[i][j].cost;
tmp = min(dp[i][j] , tmp);
}
dp[i][j] = tmp;
// cout << dp[i][j] << endl;
}
}
int ans = inf;
for(int i = 1 ; i <= t ; i++){
int value = dp[c][i] + abs(l - e[c][i].pos);
ans = min(ans , value);
}
cout << ans << endl;
}
return 0;
}

最新文章

  1. 在ASP.NET Core Web API上使用Swagger提供API文档
  2. 华硕Z97-A主板声卡设置
  3. C语言(2)
  4. C#(Winform) Http 发送数据
  5. Combine String---hdu5727 &amp;&amp;&amp; Zipper(LCS变形)
  6. Selenium2学习-004-WebUI自动化实战实例-002-百度登录
  7. .net 类型源码下载地址
  8. 国内Jquery CDN
  9. delphi 使用进度条查看浏览器状态
  10. window.onbeforeunload 如果取消, 那么javascript变量会保存
  11. Android模拟器如何加载本机地址及访问本机服务器
  12. Neutron数据库同步错误 NotImplementedError: No support for ALTER of constraints in SQLite dialect
  13. Linux下smi/mdio总线驱动
  14. python 邮件报警
  15. POJ 3449 Geometric Shapes
  16. android离线缓存技术
  17. npm install 时出现的 EACCES: permission denied 错误的可能有效的解决方案
  18. 怎样Debug Dynamics 365 CRM Plugin
  19. vue的Vuex
  20. Win7下静态编译QT5.12源码

热门文章

  1. [SharePoint][SharePoint2013循序渐进]SPS2013简介
  2. ZooKeeper分布式集群部署及问题
  3. wpf Shake
  4. Android顶部粘至视图具体解释
  5. php实现邮箱激活功能
  6. NOIp2018之前打模板出现的问题汇总
  7. ROS-动态参数
  8. C#——单元测试
  9. sql server 随机生成布尔值
  10. 使用http-server开启一个本地服务器