传送门
暴力模拟
因为每个房间之间只有一条路,所以不用什么决策或者dp
dfs出每个点经过的时间,然后比较,
cost[i][j]×(Tnow−Tpre)
与
on[i][j]+off[i][j]
哪个小就选哪个。
第一次经过一定要开灯和最后一次经过一定要关灯。所以只要经过了就需要加上
on[i][j]+off[i][j]
。
// whn6325689
// Mr.Phoebe
// http://blog.youkuaiyun.com/u013007900
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
#include <functional>
#include <numeric>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define eps 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LLINF 1LL<<50
#define speed std::ios::sync_with_stdio(false);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef complex<ld> point;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
#define CLR(x,y) memset(x,y,sizeof(x))
#define CPY(x,y) memcpy(x,y,sizeof(x))
#define clr(a,x,size) memset(a,x,sizeof(a[0])*(size))
#define cpy(a,x,size) memcpy(a,x,sizeof(a[0])*(size))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define lowbit(x) (x&(-x))
#define MID(x,y) (x+((y-x)>>1))
#define ls (idx<<1)
#define rs (idx<<1|1)
#define lson ls,l,mid
#define rson rs,mid+1,r
#define root 1,1,n
template<class T>
inline bool read(T &n)
{
T x = 0, tmp = 1;
char c = getchar();
while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
if(c == EOF) return false;
if(c == '-') c = getchar(), tmp = -1;
while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();
n = x*tmp;
return true;
}
template <class T>
inline void write(T n)
{
if(n < 0)
{
putchar('-');
n = -n;
}
int len = 0,data[20];
while(n)
{
data[len++] = n%10;
n /= 10;
}
if(!len) data[len++] = 0;
while(len--) putchar(data[len]+48);
}
//-----------------------------------
int ma[55][55],r,c,m;
vector<int> t[55][55];
pii road[3333];
int on[55][55],off[55][55],cost[55][55];
const int dir[4][2]= {0,1,0,-1,1,0,-1,0};
char str[55];
bool vis[55][55];
pii task[1111];
inline bool in(int x,int y)
{
return x>=0 && x<r && y>=0 && y<c;
}
int dfs(int x,int y,int ex,int ey,int step)
{
if(x==ex && y==ey)
{
return step;
}
for(int i=0; i<4; i++)
{
int xx=x+dir[i][0];
int yy=y+dir[i][1];
if(in(xx,yy) && ma[xx][yy] && !vis[xx][yy])
{
road[step]=mp(xx,yy);
vis[xx][yy]=1;
int temp=dfs(xx,yy,ex,ey,step+1);
if(temp!=-1)
return temp;
vis[xx][yy]=0;
}
}
return -1;
}
int main()
{
//freopen("data.txt","r",stdin);
while(scanf("%d %d %d",&r,&c,&m)!=EOF)
{
for(int i=0; i<r; i++)
{
scanf("%s",str);
for(int j=0; j<c; j++)
{
t[i][j].clear();
if(str[j]=='#')
ma[i][j]=0;
else
ma[i][j]=1;
}
}
for(int i=0; i<r; i++)
for(int j=0; j<c; j++)
read(cost[i][j]);
for(int i=0; i<r; i++)
for(int j=0; j<c; j++)
read(on[i][j]);
for(int i=0; i<r; i++)
for(int j=0; j<c; j++)
read(off[i][j]);
for(int i=0; i<m; i++)
read(task[i].first),read(task[i].second);
t[task[0].first][task[0].second].pb(0);
int time=0;
for(int i=1; i<m; i++)
{
CLR(vis,0);
vis[task[i-1].first][task[i-1].second]=1;
int step=dfs(task[i-1].first,task[i-1].second,task[i].first,task[i].second,0);
for(int j=0; j<step; j++)
t[road[j].first][road[j].second].push_back(time+j+1);
time+=step;
}
int ans=0;
for(int i=0; i<r; i++)
for(int j=0; j<c; j++)
for(int k=0; k<t[i][j].size(); k++)
{
if(k)
{
if((t[i][j][k]-t[i][j][k-1])*cost[i][j] < on[i][j]+off[i][j])
ans+=(t[i][j][k]-t[i][j][k-1])*cost[i][j];
else
ans+=on[i][j]+off[i][j];
}
else
ans+=on[i][j]+off[i][j];
}
write(ans),putchar('\n');
}
return 0;
}