【题解】codevs P1403 新三国争霸(最小生成树 dp)

联动:https://blog.youkuaiyun.com/Rem_Inory/article/details/81139322

这道题和一道叫物流运输的题非常相似,只不过变成了求最小生成树。根据这种思路我们求出w数组代表第i天到第j天没有灾害会消耗的军粮数,然后还要设一个判断数组记录在某一段时间内出现了灾害,记录下每一段时间内的最小值,然后进行dp操作就好了

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=310;
const int maxm=5010;
const int maxt=55;
int n,m,v,k,p,t;
int f[maxt];
int fa[maxn];
int w[maxt][maxt];
bool use[maxt][maxn][maxn];
struct edge
{
	int u,v,w;
}e[maxm];
int find(int x)
{
	if(fa[x]!=x) fa[x]=find(fa[x]);
	return fa[x];
}
bool cmp(const edge &a,const edge &b)
{
	return a.w<b.w;
}
bool pd(int a,int b,int x,int y)
{
	for(int i=a;i<=b;i++)
	{
		if(use[i][x][y]==true) return false;
	}
	return true;
} 
int kruskal(int a,int b)
{
	int ans=0;
	for(int i=1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值