Welcome, Guest! Sign Up RSS

Clever Space

Friday, 11.22.2024
Main » 2013 » October » 17

单调队列优化DP

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<iostream>
#include<string>
#include<cmath>
#define N 100010
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
typedef long long LL;
using namespace std;
struct node{int X,F,C;};
int cmp(node a,node b){return a.X<b.X;}
node a[N];
LL q1[N],q2[N],x[N],c[N],f[N],dp0[N],dp1[N];
int k,e,n;
int main()
{
  scanf("%d%d%d",&k,&e,&n);
  int i,j;
  FOR(i,1,n)
  {
    scanf("%d%d%d",&a[i].X,&a[i].F,&a[i].C);
  }
  sort(a+1,a+1+n,cmp);
  FOR(i,1,n) f[i]=a[i].F,c[i]=a[i].C,x[i]=a[i].X;
  FOR(i,1,k) dp0[i]=1e15;
  FOR(i,1,f[1]) dp0[i]=c[1]*i;
  dp0[0]= ... Read more »

Views: 455 | Added by: dhy0077 | Date: 10.17.2013