标签:des style http color os io java strong ar
dfs+减枝....
4 0 3 8 6 4 0 7 4 7 5 0 2 6 9 3 0 30 8 30 4 0 2 3 3 2 0 3 3 2 3 0 3 2 3 3 0 2 3 3
36 -1HintExplanation: In case #1: The Super Doge travels to Doge Planet 2 at the time of 8 and to Doge Planet 3 at the time of 12, then to Doge Planet 4 at the time of 16. The minimum sum of all arrival time is 36.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
int n,ans;
int g[40][40],deadline[40];
bool vis[40];
void dfs(int u,int alltime,int time,int num)
{
if(num==0)
{
ans=min(ans,alltime);
return ;
}
for(int i=1;i<=n;i++)
{
if(vis[i]) continue;
int T=time+g[u][i];
bool flag=true;
if(alltime+T*(num-1)>ans) continue;
for(int j=1;j<=n;j++)
{
if(vis[j]) continue;
if(deadline[j]<T)
{
flag=false;
break;
}
}
if(flag==false) continue;
vis[i]=true;
dfs(i,alltime+T,T,num-1);
vis[i]=false;
}
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(g,63,sizeof(g));
memset(vis,false,sizeof(vis));
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
scanf("%d",&g[i][j]);
for(int i=2;i<=n;i++)
scanf("%d",deadline+i);
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
ans=0x3f3f3f3f;
vis[1]=true;
dfs(1,0,0,n-1);
if(ans==0x3f3f3f3f) ans=-1;
printf("%d\n",ans);
}
return 0;
}
HDOJ 4848 Wow! Such Conquering!
标签:des style http color os io java strong ar
原文地址:http://blog.csdn.net/ck_boss/article/details/39013423