设为首页 加入收藏

TOP

HDU 4085 斯坦纳树模板题
2015-07-20 18:06:48 来源: 作者: 【 】 浏览:14
Tags:HDU 4085 斯坦 模板

Dig The Wells

Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 971 Accepted Submission(s): 416


Problem Description You may all know the famous story “Three monks”. Recently they find some places around their temples can been used to dig some wells. It will help them save a lot of time. But to dig the well or build the road to transport the water will cost money. They do not want to cost too much money. Now they want you to find a cheapest plan.
Input There are several test cases.
Each test case will starts with three numbers n , m, and p in one line, n stands for the number of monks and m stands for the number of places that can been used, p stands for the number of roads between these places. The places the monks stay is signed from 1 to n then the other m places are signed as n + 1 to n + m. (1 <= n <= 5, 0 <= m <= 1000, 0 <=p <= 5000)
Then n + m numbers followed which stands for the value of digging a well in the ith place.
Then p lines followed. Each line will contains three numbers a, b, and c. means build a road between a and b will cost c.

Output For each case, output the minimum result you can get in one line.
Sample Input
3 1 3
1 2 3 4
1 4 2
2 4 2
3 4 4 
4 1 4
5 5 5 5 1
1 5 1
2 5 1
3 5 1
4 5 1

Sample Output
6
5


题意:有n个和尚,每一个和尚一个庙,有m个村庄,p条路,每条路有费用,每一个地方打井也需要费用,求最少花多少钱可以使得所有和尚喝上水。

斯坦纳树比较裸的问题。

代码:

/* ***********************************************
Author :rabbit
Created Time :2014/7/17 0:59:57
File Name :13.cpp
************************************************ */
#pragma comment(linker, "/STACK:102400000,102400000")
#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
         
           #include 
          
            #include 
           
             #include 
            
              #include 
             
               #include 
              
                #include 
                using namespace std; #define INF 100000000 #define eps 1e-8 #define pi acosi typedef long long ll; int head[1100],tol; struct Edge{ int next,to,val; }edge[1001000]; void addedge(int u,int v,int w){ edge[tol].to=v; edge[tol].next=head[u]; edge[tol].val=w; head[u]=tol++; } int weight[1100],d[1100][1<<5],dp[1100],in[1010][1<<5]; int main() { //freopen("data.in","r",stdin); //freopen("data.out","w",stdout); int n,m,p; while(~scanf("%d%d%d",&n,&m,&p)){ memset(head,-1,sizeof(head));tol=0; for(int i=0;i
                
                  Q; for(int j=0;j
                 
                  d[v][t]+edge[e].val+weight[s]-weight[v]){ d[s][t]=d[v][t]+edge[e].val+weight[s]-weight[v]; if(!in[s][t]){ in[s][t]=1; Q.push(100000*s+t); } } } } } for(int i=1;i<(1<
                  
                   

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇链表(二)――单向链表的基本操.. 下一篇UVA 11021 - Tribles(概率递推)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: