革命之路漫漫

第一次尝试 40points spfa

 #include <bits/stdc++.h>
#define read read()
using namespace std; inline int read
{
int x=,f=;char ch=getchar();
while(ch<''||ch>'') {if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+(ch-'');ch=getchar();}
return x*f;
} const int N = ; struct edge{
int v,nxt,w;
}e[N<<]; int n,m;
int head[N],size;
int dis[N],vis[N],maxn = INT_MAX;
void add(int u,int v,int w)
{
e[++size].v = v;
e[size].w = w;
e[size].nxt = head[u];
head[u] = size;
} queue<int>q; void spfa(int s)
{
memset(dis,0x3f,sizeof(dis));
memset(head,,sizeof());
memset(vis,,sizeof(vis));
dis[s] = ;
q.push(s);
vis[s] = ;
while(!q.empty())
{
int u = q.front(); q.pop(); vis[u] = ;
for(int i = head[u]; i ; i = e[i].nxt)
{
int v = e[i].v, w = e[i].w;
if(dis[v] > dis[u] + )
{
dis[v] = dis[u] + ;
if(!vis[v])
{
q.push(v);
vis[v] = ;
}
}
}
}
} int main()
{
freopen("treasure.in","r",stdin);
n = read; m = read;
int u,v,w;
for(int i = ; i <= m; i++)
{
u = read; v = read; w = read;
add(u,v,w);
add(v,u,w); }
for(int i = ; i <= n; i++)
{
spfa(i);
int ans = ;
for(int i = ; i <= n; i++)
{
ans += dis[i] * w;
}
maxn = min(maxn , ans);
}
printf("%d",maxn);
return ;
}

第二次尝试 dfs

 #include <bits/stdc++.h>
#define read read()
using namespace std; const int N = ; int n,m;
int cost[N][N],cnt[N];
int head[N],size;
int ans = INT_MAX, mincost;
int read
{
int x = ; char ch = getchar();
while(ch < || ch > ) ch = getchar();
while(ch >= && ch <= ) { x = * x + ch - ; ch = getchar();}
return x;
} void dfs(int cur)//暴力枚举所有情况;
{
if(cur == n)
{
ans = min(ans,mincost);
return;
}
if(mincost > ans) return;
for(int i = ; i <= n; i++) //枚举出点;
{
if(!cnt[i]) continue; //还未连通的点不能当作出点;
for(int j = ; j <= n; j++) //枚举入点;
{
if(i == j || cnt[j] || cost[i][j] == 0x3f3f3f3f) continue;
mincost += cnt[i] * cost[i][j];
cnt[j] = cnt[i] + ;
dfs(cur + );
mincost -= cnt[i] * cost[i][j];
cnt[j] = ;
}
}
} int main()
{
// freopen("treasure.in","r",stdin);
n = read;m = read;
memset(cost,0x3f,sizeof(cost));
int u,v;
for(int i = ; i <= m; i++)
{
u = read; v = read;
cost[u][v] = cost[v][u] = min(read , cost[u][v]); //细节: u-v之间可能有多条路连接, 忽略其余选最短;
}
for(int i = ; i <= n; i++) //枚举起点;
{
cnt[i] = ;
dfs();
cnt[i] = ;
}
printf("%d",ans);
return ;
}

NOIP 2017 d2t2 70points的更多相关文章

  1. NOIP 2017 解题报告

    ---恢复内容开始--- NOIP 2017 的题真的很难啊,怪不得当年我这个萌新爆零了(当然现在也是萌新)越学越觉得自己什么都不会. 想要成为强者要把这些好题都弄懂弄透 至少现在6道题我都比较陌生 ...

  2. NOIP 2017 列队 - Splay - 树状数组

    题目传送门 传送点I 传送点II 题目大意 (家喻户晓的题目应该不需要大意) (我之前咋把NOIP 2017打成了NOIP 2018,好绝望) Solution 1 Splay 每行一颗Splay,没 ...

  3. 【游记】NOIP 2017

    时间:2017.11.11~2017.11.12 地点:广东省广州市第六中学 Day1 T1:看到题目,心想这种题目也能放在T1? 这个结论我之前遇到过至少3次,自己也简单证明过.初见是NOIP200 ...

  4. NOIP 2017 小凯的疑惑

    # NOIP 2017 小凯的疑惑 思路 a,b 互质 求最大不能表示出来的数k 则k与 a,b 互质 这里有一个结论:(网上有证明)不过我是打表找的规律 若 x,y(设x<y) 互质 则 : ...

  5. 历年真题 未完成(Noip 2008 - Noip 2017)

    Noip 2008 :全部 Noip 2009 :全部 Noip 2010 :AK Noip 2011 :AK Noip 2012 : Vigenère 密码,国王游戏,开车旅行 Noip 2013 ...

  6. 「NOIP 2017」列队

    题目大意:给定一个 $n times m$ 的方阵,初始时第 $i$ 行第 $j$ 列的人的编号为 $(i-1) times m + j$,$q$ 次给出 $x,y$,让第 $x$ 行 $y$ 列的人 ...

  7. NOIP 2016 D2T2 蚯蚓](思维)

    NOIP 2016 D2T2 蚯蚓 题目大意 本题中,我们将用符号 \(\lfloor c \rfloor⌊c⌋\) 表示对 \(c\) 向下取整,例如:\(\lfloor 3.0 \rfloor = ...

  8. 洛谷 P3951 NOIP 2017 小凯的疑惑

    洛谷 P3951 NOIP 2017 小凯的疑惑 题目描述 小凯手中有两种面值的金币,两种面值均为正整数且彼此互素.每种金币小凯都有 无数个.在不找零的情况下,仅凭这两种金币,有些物品他是无法准确支付 ...

  9. NOIP 2017 提高组 day1t2 时间复杂度

    P3952 时间复杂度 标签 NOIp提高组 2017 时空限制 1000ms / 128MB 小明正在学习一种新的编程语言 A++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂 ...

随机推荐

  1. centos 6.5 DNS服务器 搭建

    一.DNS 介绍 DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,DNS协议运行在UDP协议之上,使用端口号53(Domain), 95 ...

  2. CentOS 下环境变量

    1. 显示环境变量HOME(不要把一个#号输进去了,#代表用户名) # echo #HOME /home/redbooks 2. 设置一个新的环境变量hello # export HELLO=&quo ...

  3. f5 SNMP配置

    1.选择监控终端 2.配置团体名称:

  4. 【C++】:STL迭代器使用---[容器::iterator iter;]

    参考文章:http://blog.csdn.net/qq_23100787/article/details/51388163 迭代器这种东西,就是为了使访问简单!! 容器::iterator iter ...

  5. MySQL 5.6.4 中TIMESTAMP with implicit DEFAULT value is deprecated 错误

    [Warning] TIMESTAMP with implicit DEFAULT value is deprecated.   在免安装版mysql安装过程中出现:[Warning] TIMESTA ...

  6. C#设计模式-2工厂方法模式(Factory Method)

    什么是工厂模式?类比生活中的概念,当我们需要打电话的时候,我们需要一部手机,我们通常会选择直接去卖手机的实体店买.但在程序设计中,当我们需要调用一个类(PhoneA或PhoneB)的方法的时候,我们往 ...

  7. c# 子线程打开子窗体

    下边是在子线程打开子窗口,结果跑到else 里边了跨线程操作窗体控件InvokeRequired失效,无法用于打开子窗体,addonetwo.InvokeRequired,访问不了呢? 大神知道帮忙回 ...

  8. 转easyui datagrid 前台分页的实现

    easyui datagrid 前台分页的实现java采用的版本 来源:本站原创 js知识 超过5,090人围观 暂无评论 使用easyui分页,有后台服务器端实现和前台浏览器端实现.服务器端实现按规 ...

  9. PAT 1043 输出PATest(20)(代码+思路)

    1043 输出PATest(20)(20 分) 给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按"PATestPATest...."这样的顺序输出 ...

  10. Android——图片视图(ImageView)、状态开关按钮(ToggleButton)、时钟、图片透明度、滚动和时间选择器

    activity_ui1.xml dth="wrap_content" android:layout_height="wrap_content" android ...