bzoj 5056: OI游戏 最短路树的计数
OI游戏
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 196 Solved: 159
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
2
01
10
Input2
4
0123
1012
2101
3210
Sample Output
1
Output2
6
HINT
Source
记录方案,乘法原理
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue> #define N 57
#define M 2507
#define mod 1000000007
#define ll long long
#define inf 1000000007
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<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
} int n;
int cnt,hed[N],nxt[M],rea[M],val[M];
int dis[N],flag[N];
char ch[]; void add(int u,int v,int z)
{
nxt[++cnt]=hed[u];
hed[u]=cnt;
rea[cnt]=v;
val[cnt]=z;
}
void Spfa()
{
for (int i=;i<=n;i++)
dis[i]=inf,flag[i]=;
queue<int>q;q.push();dis[]=,flag[]=;
while(!q.empty())
{
int u=q.front();q.pop();
for (int i=hed[u];i!=-;i=nxt[i])
{
int v=rea[i],fee=val[i];
if (dis[v]>dis[u]+fee)
{
dis[v]=dis[u]+fee;
if (!flag[v])
{
q.push(v);
flag[v]=;
}
}
}
flag[u]=;
}
}
int main()
{
memset(hed,-,sizeof(hed));
n=read();
for (int i=;i<=n;i++)
{
scanf("%s",ch+);
int t=strlen(ch+);
for (int j=;j<=t;j++)
if (ch[j]!='') add(i,j,ch[j]-'');
}
Spfa();
ll ans=;
for (int i=;i<=n;i++)
{
ll tot=;
for (int j=hed[i];j!=-;j=nxt[j])
{
int v=rea[j],fee=val[j];
if (dis[i]==dis[v]+fee) tot++;
}
ans=(ans*tot)%mod;
}
printf("%lld",ans);
}
bzoj 5056: OI游戏 最短路树的计数的更多相关文章
- bzoj 5056: OI游戏
5056: OI游戏 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 204 Solved: 162[Submit][Status][Discuss] D ...
- BZOJ5056 OI游戏[最短路树]
有生以来做过的bzoj比A+B还简单的最水的题.(确信) 不解释. UPD:据说这题正解应当是矩阵树定理?但是这个不是用来最小生成树计数的么?有生之年会补的. #include<iostream ...
- CF1005F Berland and the Shortest Paths 最短路树计数
问题描述 LG-CF1005F 题解 由题面显然可得,所求即最短路树. 所以跑出最短路树,计数,输出方案即可. \(\mathrm{Code}\) #include<bits/stdc++.h& ...
- 【BZOJ 1880】 [Sdoi2009]Elaxia的路线 (最短路树)
1880: [Sdoi2009]Elaxia的路线 Description 最近,Elaxia和w**的关系特别好,他们很想整天在一起,但是大学的学习太紧张了,他们 必须合理地安排两个人在一起的时间. ...
- 【BZOJ5056】OI游戏 最短路+有向图生成树计数
[BZOJ5056]OI游戏 Description 小Van的CP最喜欢玩与OI有关的游戏啦~小Van为了讨好她,于是冥思苦想,终于创造了一个新游戏. 下面是小Van的OI游戏规则: 给定一个无向连 ...
- BZOJ 2725 [Violet 6]故乡的梦 线段树+最短路树
\(\color{#0066ff}{ 题目描述 }\) \(\color{#0066ff}{输入格式}\) \(\color{#0066ff}{输出格式}\) \(\color{#0066ff}{输入 ...
- BZOJ1975[Sdoi2010]魔法猪学院——可持久化可并堆+最短路树
题目描述 iPig在假期来到了传说中的魔法猪学院,开始为期两个月的魔法猪训练.经过了一周理论知识和一周基本魔法的学习之后,iPig对猪世界的世界本原有了很多的了解:众所周知,世界是由元素构成的:元素与 ...
- CF1076D Edge Deletion 最短路树
问题描述 Codeforces 洛谷(有翻译) 题解 最短路树,是一棵在最短路过程中构建的树. 在\(\mathrm{Dijkstra}\)过程中,如果最终点\(y\)是由点\(x\)转移得到的,则在 ...
- hdu 3409 最短路树+树形dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3409 参考博客:http://www.cnblogs.com/woaishizhan/p/318981 ...
随机推荐
- 团队作业——项目Alpha版本发布
---恢复内容开始--- https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1 https://edu.cnblogs.com ...
- Git初始化仓库
Git global setup: git config --global user.name "再见理想" git config --global user.email &quo ...
- MySQL使用INSERT插入多条记录
MySQL使用INSERT插入多条记录,应该如何操作呢?下面就为您详细介绍MySQL使用INSERT插入多条记录的实现方法,供您参考. 看到这个标题也许大家会问,这有什么好说的,调用多次INSERT语 ...
- 如何将oracle查询的结果传输给变量
如何将oracle查询的结果传输给变量 1. sqlplus查询时的变量设置 set echo off; #控制start命令不列出命令文件中的每一命令 set feedback off; #显示由查 ...
- Vim如何显示和关闭行号
显示行号: set nu 去除行号: set nonu
- 多线程辅助类之CyclicBarrier(四)
CyclicBarrier是一个线程辅助类,和<多线程辅助类之CountDownLatch(三)>功能类似,都可以实现一组线程的相互等待.要说不通点,那就是CyclicBarrier在释放 ...
- nrf51822微信开发入门学习笔记1:开始前的准备
参考:(id:love--baby)https://blog.csdn.net/hunhun1122/article/details/68922493 微信硬件平台:https://iot.weixi ...
- 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 ...
- Splay的用法
splay区间增减查询 #include<cstdio> #include<algorithm> using namespace std; ; const int INF = ...
- HDU 3966 RE 树链剖分 线段树 Aragorn's Story
题意: 给出一棵树,每个顶点上有一个权值. 操作:选择一条路径,并将路径上所有的点的权值同时加或减某个数. 查询:某个点的当前权值 分析: 树链剖分完毕后,就是简单的线段树区间更新. 提交的时候注意要 ...