Codeforces 489E Hiking(普通01分数规划加DP)
来源:互联网 发布:阿尔法营软件下载 编辑:程序博客网 时间:2024/05/13 02:49
题意跟普通01分数规划差不多,就是ai变成了 ,而这个是跟你选的上一个有关系,那么判断的时候可以用一个DP数组代表从0开始停在i位置的最小ai-L×bi值,总复杂度是n^2logn。
AC代码:
//#pragma comment(linker, "/STACK:102400000,102400000")#include<cstdio>#include<ctype.h>#include<algorithm>#include<iostream>#include<cstring>#include<vector>#include<cstdlib>#include<stack>#include<cmath>#include<queue>#include<set>#include<map>#include<ctime>#include<string.h>#include<string>#include<sstream>#include<bitset>using namespace std;#define ll long long#define ull unsigned long long#define eps 1e-8#define NMAX 1000005#define MOD 1000000007#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1#define PI acos(-1)template<class T>inline void scan_d(T &ret){ char c; int flag = 0; ret=0; while(((c=getchar())<'0'||c>'9')&&c!='-'); if(c == '-') { flag = 1; c = getchar(); } while(c>='0'&&c<='9') ret=ret*10+(c-'0'),c=getchar(); if(flag) ret = -ret;}double dp[1005];int x[1005],b[1005],n,l,pre[1005];bool check(double p){ for(int i = 1; i <= n; i++) { double ha = 1005; for(int j = 0; j < i; j++) { if(ha > dp[j]+sqrt(abs(l-x[i]+x[j]))-p*b[i]) { ha = dp[j]+sqrt(abs(l-x[i]+x[j]))-p*b[i]; pre[i] = j; } } dp[i] = ha; } if(dp[n] < 0) return true; return false;}void print(int pos){ if(pos == 0) return; print(pre[pos]); printf("%d%c",pos,(pos==n)?'\n':' ');}int main(){#ifdef GLQ freopen("input.txt","r",stdin);// freopen("o4.txt","w",stdout);#endif // GLQ scanf("%d%d",&n,&l); for(int i = 1; i <= n; i++) scanf("%d%d",&x[i],&b[i]); double l=0,r=1005; while(abs(r-l) > eps) { double mid = (r+l)/2; if(check(mid)) r = mid; else l = mid; } print(n); return 0;}
0 0
- Codeforces 489E Hiking(普通01分数规划加DP)
- codeforces 489e Hiking dp+01分数规划+二分
- codeforces 277.5 E.Hiking 01分数规划
- Codeforces Round #277.5(Div. 2)E. Hiking【Dp+01分数规划】
- 【Codeforces】 489E Hiking
- CodeForces 489E Hiking
- Codeforces 489E Hiking
- CodeForces 489E Hiking
- Codeforce 489E(dp+01分数规划)
- Codeforces Round #277.5 (Div. 2) E. Hiking(二分 DP)
- POJ 2976 Dropping tests(普通01分数规划)
- codeforces 710E Generate a String [dp]【动态规划】
- 2013编程之美挑战赛复赛---R2_B:招聘(01分数规划+DP)
- [BZOJ]4753: [Jsoi2016]最佳团体 01分数规划+树形DP
- CodeForces - 49E Common ancestor(dp)
- CodeForces 148E Porcelain(dp+背包)
- Codeforces 598E:Chocolate Bar(DP)
- Codeforces 166E Tetrahedron(dp)
- SQLitePersistentObject使用需要注意的几个问题
- phonegap开发总结(上)
- 我们熟悉的106短信的水好深啊
- POJ 2976 Dropping tests(普通01分数规划)
- SVN服务器的搭建
- Codeforces 489E Hiking(普通01分数规划加DP)
- OpenGL学习日记-2014.11.26--简单裁剪
- git取消文件跟踪
- OC面向对象思想Object Oriented:类与对象
- ODBC API开发教程1
- 需求实例_20141127
- 阿里四大行的发生的报名妇女报十多年
- 需求案例_20141127
- liferay跳转页面