hdoj3665【简单DFS】
2024-09-08 09:16:59
题意:
略。
思路:
n就10而已,没有环,搜一下就好了。。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod=1e9+7;
const int N=10+10;
const int INF=0x3f3f3f3f;
int ma[N][N];
bool flag[N];
bool vis[N];
int ans;
int n;
void init()
{
memset(ma,INF,sizeof(ma));
memset(flag,0,sizeof(flag));
memset(vis,0,sizeof(vis));
}
void dfs(int x,int sum)
{
if(sum>=ans)
return;
if(flag[x]==1)
{
ans=min(ans,sum);
return;
}
for(int i=0;i<n;i++)
{
if(i!=x&&!vis[i]&&ma[x][i]!=INF)
{
vis[i]=1;
dfs(i,sum+ma[x][i]);
vis[i]=0;
}
}
}
int main()
{
while(~scanf("%d",&n))
{
init();
int num;
int k,x,y;
for(int i=0;i<n;i++)
{
scanf("%d%d",&num,&k);
if(k==1)
flag[i]=1;
for(int j=0;j<num;j++)
{
scanf("%d%d",&x,&y);
ma[i][x]=ma[x][i]=min(ma[i][x],y);
}
}
if(flag[0])
{
puts("0");
continue;
}
ans=INF;
vis[0]=1;
dfs(0,0);
printf("%d\n",ans);
}
return 0;
}
最新文章
- Windows7安装 .net framework 4.0
- Python3 的json 和 PHP的json
- NYOJ 485
- listview选中没有效果
- CentOS 配置solr中文分词器
- MyISAM与InnoDB的索引实现
- 使用SSMS 2014将本地数据库迁移到Azure SQL Database
- static作用——The static effect
- Laravel Eloquent ORM
- Remove Duplicate Letters
- 设置TextView水平居中显示
- ASP.NET CORE 1.0 初次接触
- mac中使用终端生成RSA私钥和公钥文件
- The Speed 歌词
- win10更新系统后,无法远程访问的bug
- Mybatis 使用了哪些设计模式?
- 100-days: eighteen
- wqCms6.0在IIS6的Getshell
- Qt简单项目--加法计算器(详细代码注释)
- 【慕课网实战】Spark Streaming实时流处理项目实战笔记五之铭文升级版