ZOJ1894 POJ2465 Adventures in Moving - Part IV
来源:互联网 发布:屏幕着火软件下载 编辑:程序博客网 时间:2024/05/19 13:56
典型的DP题,dp[i][j]表示的是到了第i个站的时候,总共油缸里还剩下j油的最小费用。记得把起始和终点都要列进去。
输入真恶心
/******************************************************************************* # Author : Neo Fung # Email : neosfung@gmail.com # Last modified: 2012-04-16 21:41 # Filename: ZOJ1894 POJ2465 Adventures in Moving - Part IV.cpp # Description : ******************************************************************************/#ifdef _MSC_VER#define DEBUG#define _CRT_SECURE_NO_DEPRECATE#endif#include <fstream>#include <stdio.h>#include <iostream>#include <string.h>#include <string>#include <limits.h>#include <algorithm>#include <math.h>#include <numeric>#include <functional>#include <ctype.h>#define MAX 110#define inf 20000000using namespace std;int dp[MAX][MAX*2],dis[MAX],price[MAX],total;int main(void){#ifdef DEBUG freopen("../stdin.txt","r",stdin);freopen("../stdout.txt","w",stdout); #endif char str[100];while(~scanf("%d",&total)){int n=1;getchar();while(gets(str) && strlen(str)){sscanf(str,"%d%d",&dis[n],&price[n]);++n;}dis[n]=total;price[n++]=inf;for(int i=0;i<MAX;++i)for(int j=0;j<MAX*2;++j)dp[i][j]=inf;dp[0][100]=0;for(int i=1;i<n;++i)for(int j=0;j<=200;++j){for(int k=dis[i]-dis[i-1];k<=200;++k)if(dp[i-1][k]!=inf){if(k-(dis[i]-dis[i-1])>j)break;elsedp[i][j]=min(dp[i][j],dp[i-1][k]+(j-(k-dis[i]+dis[i-1]))*price[i]);}}int ans=dp[n-1][100];if(ans==inf)printf("Impossible\n");elseprintf("%d\n",ans);}return 0;}
- ZOJ1894 POJ2465 Adventures in Moving - Part IV
- 背包 POJ2465 Adventures in Moving
- 10201 - Adventures in Moving - Part IV
- uva 10201 Adventures in Moving - Part IV
- UVA 10201 Adventures in Moving - Part IV
- poj 2465 Adventures in Moving - Part IV
- UVA 10201 Adventures in Moving - Part IV
- POJ 2465 Adventures in Moving - Part IV
- UVA 10201 Adventures in Moving - Part IV
- 10201 - Adventures in Moving - Part IV
- uva 10201 Adventures in Moving - Part IV
- UVA - 10201 Adventures in Moving - Part IV
- uva10201 - Adventures in Moving - Part IV
- UVA10201 - Adventures in Moving - Part IV
- uva 10201 - Adventures in Moving - Part IV
- Adventures in Moving - Part IV+uva+dp
- UVA - 10201 Adventures in Moving - Part IV
- UVA - 10201 Adventures in Moving - Part IV
- [转载自 李国杰] 对计算机科学的反思
- 今天又回jxd了,明早上从my飞。
- HashSet、LinkedHashSet和TreeSet
- 2012C++程序设计实验报告【9.1】
- svn重设日志内容
- ZOJ1894 POJ2465 Adventures in Moving - Part IV
- [转]Silverlight开发常见的一个小问题:2103错误
- 第九周 任务三
- Scribe Insight 安装的一些问题
- 第九周作业任务二
- VirtualBox下RedHat不能使用Ctrl+C快捷键解决
- Smooth 函数 平滑处理函数 OpenCV
- GetFullPathName函数使用
- 表单验证的一些东西