deque is faster !

This commit is contained in:
Kirigaya Kazuto 2016-08-23 16:55:32 +08:00 committed by GitHub
parent e6db2c3a9e
commit 548b8b2fa2

View File

@ -2,7 +2,7 @@
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
using namespace std;
#define MAXWORKER 110
@ -20,10 +20,6 @@ bool operator < (const _worker& inca,const _worker& incb)
_worker worker[MAXWORKER];
int dp[MAXWORKER][MAXBENCH];
int static_list[MAXBENCH];
int static_list_front;
int static_list_end;
int main()
{
int N,K;
@ -51,11 +47,8 @@ int main()
for(int i=1;i<=K;i++)
{
dprintf(">>>>>>> i=%d\n",i);
//list<int> pbus;
static_list_front=0;
static_list[0]=max(0,worker[i].S-worker[i].L);
static_list_end=1;
deque<int> pbus;
pbus.push_back(max(0,worker[i].S-worker[i].L));
for(int j=1;j<=N;j++)
{
dprintf(">>> j=%d (i=%d)\n",j,i);
@ -66,22 +59,21 @@ int main()
/// !!! Must include 'equal' (=) !!!
if(worker[i].L+worker[i].S<=j) continue;
while(static_list_front<static_list_end&&static_list[static_list_front]+worker[i].L<j)
static_list_front++;
while(!pbus.empty()&&pbus.front()+worker[i].L<j) pbus.pop_front();
if(j<worker[i].S)
{
while(static_list_front<static_list_end&&
dp[i-1][static_list[static_list_end-1]]-static_list[static_list_end-1]*worker[i].P
while(!pbus.empty()&&
dp[i-1][pbus.back()]-pbus.back()*worker[i].P
<
dp[i-1][j]-j*worker[i].P
)
static_list_end--;
static_list[static_list_end++]=j;
pbus.pop_back();
pbus.push_back(j);
continue;
}
dp[i][j]=max(dp[i][j],dp[i-1][static_list[static_list_front]]+worker[i].P*(j-static_list[static_list_front]));
dp[i][j]=max(dp[i][j],dp[i-1][pbus.front()]+worker[i].P*(j-pbus.front()));
/*
/// Output DP