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