革命之路漫漫

第一次尝试 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. XHXJ's LIS(数位DP)

    XHXJ's LIS http://acm.hdu.edu.cn/showproblem.php?pid=4352 Time Limit: 2000/1000 MS (Java/Others)     ...

  2. QT注意事项(持续更新...)

    同样要注意new和delete的问题: is not a member of QApplication:这个错误可能是找不到信号或槽函数: 想用到信号槽,必须至少继承QObject类,并在类第一行写上 ...

  3. 解决com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭

    com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭. at com.microsoft.sqlserver.jdbc.SQLServerEx ...

  4. [leetcode]304. Range Sum Query 2D - Immutable二维区间求和 - 不变

    Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...

  5. android轮播图的实现原理

    1.轮播图的点:RadioGroup,根据网络请求的数据,解析得到的图片的个数,设置RadioGroup的RadioButton的个数. 2.轮播图的核心技术:用Gallery来存放图片,设置适配器. ...

  6. 使用JFinal实现使用MVC获取表单中的数据并将提示信息返回给另一jsp页面。

    1.包结构 2.我们需要对web.xml进行配置: <?xml version="1.0" encoding="UTF-8"?> <web-a ...

  7. props传递数据

    一.传递数据 1.props 传入单数据 就像 data 一样,prop 可以用在模板内,同样也可以在 vm 实例中像“this.message”这样使用 <template> <d ...

  8. python 数据类型 总结

    按存储空间的占用分(从低到高) 数字 字符串 集合:无序,即无序存索引相关信息 元组:有序,需要存索引相关信息,不可变 列表:有序,需要存索引相关信息,可变,需要处理数据的增删改 字典:无序,需要存k ...

  9. vs的【warning C4996:'fopen': This function or variable may be unsafe】解决方案

    编译警告:warning C4996 与 Security Enhancements in the CRT 将过去的工程用VS2005打开的时候.你有可能会遇到一大堆的警告:warning C4996 ...

  10. c#启动windows服务问题总结

    程序以管理员权限运行的原因 在Vista 和 Windows 7 及更新版本的操作系统,增加了 UAC(用户账户控制) 的安全机制,如果 UAC 被打开,用户即使以管理员权限登录,其应用程序默认情况下 ...