POJ2288 Islands and Bridges

POJ 2288 Islands and Bridges (TSP 状态压缩DP) Islands and Bridges(POJ 2288) Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 11563 Accepted: 3034 Description Given a map of islands and bridges that connect these islands,... 阅读详情

题意:求一个回路(就是从这点出发,每个点只允许经过一次,),球要权值最大。。。权值来法有3种。。

1,经过一个点就加上这个店的权值,2,回路如果是Ci,Ci+1,加上Vi*Vi+1,3,路径中的连续三个点:CiCi+1Ci+2,若在图中,构成了回路,则要加上Vi*Vi+1*Vi+2。。

状态其实还是很好想的,dp[state][i][j],state表示状态,i表示上一个点,j表示当前点。。

然后TSP转移就是,这里初始化就是有两个点才能初始化。。

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll __int64
using namespace std;
const int MAXN=10000;
ll dp[MAXN][13][13];
ll ways[MAXN][13][13];	//记录个数的
int a[13];
int mp[13][13];
int main()
{
	int t,n,m,i,j,k,kk;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&m);
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		memset(mp,0,sizeof(mp));
		memset(ways,0,sizeof(ways));
		memset(dp,-1,sizeof(dp));
		int x,y;
		while(m--)
		{
			scanf("%d%d",&x,&y);
			x--,y--;
			mp[x][y]=mp[y][x]=1;
			dp[(1<<x)|(1<<y)][x][y]=a[x]+a[y]+a[x]*a[y];
			dp[(1<<x)|(1<<y)][y][x]=a[x]+a[y]+a[x]*a[y];
			ways[(1<<x)|(1<<y)][x][y]=1;
			ways[(1<<x)|(1<<y)][y][x]=1;
		}
		if(n==1)
		{
			printf("%d 1\n",a[0]);
			continue;
		}
		for(i=0;i<(1<<n);i++)
		{
			for(j=0;j<n;j++)
			{
				if(!((1<<j)&i))//j是第一个点,也就是上一个点,状态一定要含j
					continue;
				for(k=0;k<n;k++)
				{
					if(!((1<<k)&i)) //k是第二个点,当前点,状态也要包含
						continue;
					if(j==k)
						continue;
					if(dp[i][j][k]<0)	//不存在这种情况,也就是没有初始,表示这两点之间没有边
						continue;
					for(kk=0;kk<n;kk++)
					{
						if(i&(1<<kk))	//要转移到这个点,之前要没有走过
							continue;
						if(k==kk||!mp[kk][k])	//和第二个点必须相连
							continue;
						ll temp=dp[i][j][k]+a[kk]+a[k]*a[kk];
						if(mp[j][kk])	//成了一条回路
							temp+=a[j]*a[k]*a[kk];
						int next=i|(1<<kk);
						if(temp>dp[next][k][kk])
						{
							dp[next][k][kk]=temp;
							ways[next][k][kk]=ways[i][j][k];
						}
						else if(temp==dp[next][k][kk])
						{
							ways[next][k][kk]+=ways[i][j][k];
						}
					}
				}
			}
		}
		ll ans=0;
		ll ansmax=0;
		int state=(1<<n)-1;
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				if(!mp[i][j])
					continue;
				if(dp[state][i][j]>ans)
				{
					ans=dp[state][i][j];
					ansmax=ways[state][i][j];
				}
				else if(dp[state][i][j]==ans)
					ansmax+=ways[state][i][j];
			}
		}
		printf("%I64d %I64d\n",ans,ansmax/2);
	}
	return 0;
}

2.1 量子精密测量:SERF原子陀螺仪中的核自旋-电子自旋强耦合机制 本文深入解析了SERF原子陀螺仪中核自旋-电子自旋强耦合机制的核心原理与应用。通过量子精密测量技术,SERF陀螺仪实现了超高精度的惯性导航,其独特的磁场自补偿和拉莫尔进动特性使其在弱磁场环境下表现出色。文章还探讨了关键技术突破和前沿进展,展示了量子精密测量在惯性导航领域的巨大潜力。 阅读详情

相关推荐

【Unity3D优化】优化内置shader的内存占用

在打AB包的过程中,并不会把这些Built-in的shader单独打包,并与材质球和预设体做好依赖,因此打AB包时,Unity会自行在材质球和预制体的AB包内每一个都包含进去用到的Built-in的Shader,而且运行时,由于加载的是不同的AB包,shader也是不同的实例,占用的也是多份内存。结合项目特点可以分析,由于项目里使用了大量的粒子特效,一些特殊的效果,会给特效师写定制的shader,但是这些常见的效果,特效师直接使用了Unity Built-in的shader。继续优化内存占用。

a310989583的专栏 2312

poj 2288

<br /> Islands and BridgesTime Limit: 4000MS Memory Limit: 65536KTotal Submissions: 5733 Accepted: 1455<br />DescriptionGiven a map of islands and bridges that connect these islands, a Hamilton path, as we all know, is a path along the bridges such that it

志当存高远 715

Altium Concord Pro 的应用范围,安装,和使用范围

Altium Concord Pro 的应用范围,安装,和使用范围。保证满足两者软件的最低安装要求。 Altium Concord Pro 是配合Digapcb,和MCAD,Altium 和相应机械设计软件的基础和交换桥梁

hanzhaos的博客 1120

POJ 2288 Islands and Bridges

Islands and Bridges Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 10589   Accepted: 2765 Description Given a map of islands and bridges that connect these

overload1997 397

Proteus仿真AT89C51驱动DHT11:温湿度数据采集与LCD1602显示的5个调试坑点总结

本文总结了在Proteus仿真环境下使用AT89C51驱动DHT11温湿度传感器并通过LCD1602显示的5个常见调试坑点,包括DHT11时序问题、LCD1602初始化错误、数据校验失败、仿真特有差异及系统稳定性问题,提供了详细的解决方案和优化代码示例,帮助开发者高效完成温湿度采集项目。

weixin_30335575的博客 355

Silvaco TCAD仿真4——DeckBuild实战:从示例库到自定义设计

本文详细介绍了Silvaco TCAD仿真工具DeckBuild的实战应用,从示例库的使用到自定义设计的全过程。通过具体案例和参数修改技巧,帮助用户快速掌握TCAD仿真技术,提升半导体器件设计的效率和精度。特别适合需要从基础入门到进阶操作的工程师和研究人员。

weixin_29284657的博客 434

【POI 2010】Bridges

算法标签:混合图欧拉回路+二分+网络流

forever_dreams的博客 327

2026华为OD面试题084:贪心的商人

商人经营一家店铺,有 `number` 种商品。由于仓库限制,每件商品的最大持有数量是 `item[index]`。 每种商品每天有一个价格 `item_price[item_index][day]`。通过对商品买进和卖出获取利润,请给出商人在 `days` 天内能获取到的最大利润。 注:同一件商品可以反复买进和卖出。 输入描述: - 第一行输入商品数量 `number` - 第二行输入商人售货天数 `days` - 第三行输入 `number` 个整数,表示每件商品的最大持有数量 `item[in

琅嬛福地 273

POJ2288 Islands and Bridges

状压DP 哈密顿路径

a free man 608

挂载(Mount)是什么意思

挂载 = 把一个存储设备或文件系统“接入”到现有的目录树,使其内容能够被访问。

天赐好车的博客 288

基于摩尔线程 S80 显卡在 Ubuntu 系统下双卡交火部署 DeepSeek

curl -X POST -H "Content-Type: application/json" -d '{"prompt": "你的问题"}' http://localhost:11434/api/generate。curl -X POST -H "Content-Type: application/json" -d '{"prompt": "你的问题"}' http://localhost:11434/api/generate。- 为避免模型占用系统盘空间,可将模型存储路径修改到其他磁盘。

靡不有初,鲜克有终 1195

poj 2288 Islands and Bridges

#include #include #include #include using namespace std; //poj 2288 Islands and Bridges int n,m; int a[15]; int con[15][15]; __int64 dp[1ans) { ans=dp[(1

birdforever的专栏 530

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

poj -- 2288 Islands and Bridges

题意:给你n个岛屿,m条路,每个

风儿-zsj的专栏 564

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

poj 2288 Islands and Bridges ——状压DP

题目:http://poj.org/problem?id=2288 状压挺明显的; 一开始写了(记忆化)搜索,但一直T; #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typ...

aodan5477的博客 160

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

POJ 2288 Islands and Bridges (状压dp)

文章目录POJ 2288 Islands and Bridges (状压dp)原题面Islands and Bridges输入输出样例输入样例输出题意解释题解题解代码 POJ 2288 Islands and Bridges (状压dp) 西安EC Final 之后,我第一学年的ICPC-CCPC之旅就算结束了。一年的比赛暴露了自己太多的问题,希望自己能坚持写博客来提升自己的能力,也为了督促自己备战2021-2022赛季的比赛。 原题面 Islands and Bridges Given a map of

weixin_44539230的博客 424

poj 2288 Islands and Bridges

题目链接:http://poj.org/problem?id=2288 题目思路:TSP问题,不过要注意两个地方,n=1,路径数要用int64,悲剧啊,变量居然冲突了,害得我检查了一个小时; #include #include #include #include #include #include #include #include #include #include #include usi

Wings_of_Liberty的专栏 641

poj 2288 Islands and Bridges

Islands and Bridges Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 7821   Accepted: 2003 Description Given a map of islands and bridges that connect these isl

记录成长的点点滴滴. . . . . 1426

poj 2288Islands and Bridges

#include<stdio.h> #include<string.h> #include<algorithm> #include<vector> #include<cmath> #include<iostream> using namespace std; typedef long long ll; const int maxn=100100; typedef long long ll;int w

qq_31664927的博客 318

POJ - 2288 Islands and Bridges

比较裸的状压,cnt没开 long long WA到死。。。 还要注意一下n为1的情况。 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #define fi first 5 #define se second 6 #define mk...

94
上一篇: HDU3001 Travelling
下一篇: ZOJ3471 Most Powerful
eeeaaaaa
博客等级 码龄12年 2粉丝 155原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值