HDU 4175 Class Schedule (暴力+一点dp)
题意:有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;
}
HDU 4175 Class Schedule (暴力+一点dp)的更多相关文章
- HDU 1024 Max Sum Plus Plus --- dp+滚动数组
HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...
- HDU 1231 最大连续子序列 --- 入门DP
HDU 1231 题目大意以及解题思路见: HDU 1003题解,此题和HDU 1003只是记录的信息不同,处理完全相同. /* HDU 1231 最大连续子序列 --- 入门DP */ #inclu ...
- hdu 4778 Gems Fight! 博弈+状态dp+搜索
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4102743.html 题目链接:hdu 4778 Gems Fight! 博弈+状态dp+搜 ...
- hdu 4514 并查集+树形dp
湫湫系列故事——设计风景线 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- hdu 3247 AC自动+状压dp+bfs处理
Resource Archiver Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Ot ...
- hdu 2825 aC自动机+状压dp
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 3433 A Task Process 二分+dp
A Task Process Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)
二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...
- [HDU 5293]Tree chain problem(树形dp+树链剖分)
[HDU 5293]Tree chain problem(树形dp+树链剖分) 题面 在一棵树中,给出若干条链和链的权值,求选取不相交的链使得权值和最大. 分析 考虑树形dp,dp[x]表示以x为子树 ...
随机推荐
- rpc框架--grpc-java
rpc框架--grpc-java grpc源码:https://github.com/grpc/grpc-java/releases/tag/v1.0.0 gradle下载:https://gradl ...
- VMWare虚拟机下为Ubuntu 12.04.1网络设置(NAT方式)
NAT方式: 虚拟机能够上外网,能够訪问宿主计算机所在网络的其它计算机(反之不行). 第一步:设置虚拟机vmware网络參数 (1)打开虚拟机,选择菜单"编辑">" ...
- .net mvc Model 验证总结
ASP.NET MVC4中的Model是自验证的,这是通过.NET4的System.ComponentModel.DataAnnotations命名空间完毕的. 我们要做的仅仅是给Model类的各属性 ...
- SqlServer Function 实例
① sql server function 创建 这里使用一个计算年龄精确到分的function作为一个demo, create Function [dbo].[fn_GetAge] ( @BIRTH ...
- C# web api 中过滤器的使用
一.开篇 Fiter在Web API中经常会用到,主要用于记录日志,安全验证,全局错误处理等:Web API提供两种过滤器的基本类型:actionfilterattribute,exceptionfi ...
- Python 递归和二分查找
# 二分查找l1 = [2,3,5,10,15,16,18,22,26,30,32,35,41,42,43,55,56,66,67,69,72,76,82,83,88] def two_search( ...
- const,var,let 区别
js中const,var,let区别 1.const定义的变量不可以修改,而且必须初始化. 声明的是常量 1 const b = 2;//正确 2 // const b;//错误,必须初始化 3 co ...
- 使用 Sublime 或其他编辑器调试 Tampermonkey 油猴脚本
作者说由于 Chrome 安全限制,没办法调用外部编辑器调试,但提供了一个间接办法,那就是脚本中使用@require file:///引入本地文件的形式,具体的方法是 打开 chrome://exte ...
- 页面定制CSS代码初探(四):cnblogs使用Github引用样式
前言 对于用惯了Github的人来说,眼里的引用应该是这样的 "Talk is cheap. Show me the code" -- Linus Torvalds 然而实际上cn ...
- 关于C++程序运行程序是出现的this application has requested the runtime to terminate it in an unusual way. 异常分析
今天运行程序是出现了this application has requested the runtime to terminate it in an unusual way. 的异常报告,以前也经常 ...