Deleting Edges

                                                                                 Time Limit: 2000/1000 MS (Java/Others)    Memory
Limit: 131072/131072 K (Java/Others)

                                                                                                                 Total Submission(s): 18    Accepted Submission(s): 9

Problem Description
Little Q is crazy about graph theory, and now he creates a game about graphs and trees.

There is a bi-directional graph with n nodes,
labeled from 0 to n−1.
Every edge has its length, which is a positive integer ranged from 1 to 9.

Now, Little Q wants to delete some edges (or delete nothing) in the graph to get a new graph, which satisfies the following requirements:

(1) The new graph is a tree with n−1 edges.

(2) For every vertice v(0<v<n),
the distance between 0 and v on
the tree is equal to the length of shortest path from 0 to v in
the original graph.

Little Q wonders the number of ways to delete edges to get such a satisfied graph. If there exists an edge between two nodes i and j,
while in another graph there isn't such edge, then we regard the two graphs different.

Since the answer may be very large, please print the answer modulo 109+7.
 
Input
The input contains several test cases, no more than 10 test cases.

In each test case, the first line contains an integer n(1≤n≤50),
denoting the number of nodes in the graph.

In the following n lines,
every line contains a string with n characters.
These strings describes the adjacency matrix of the graph. Suppose the j-th
number of the i-th
line is c(0≤c≤9),
if c is
a positive integer, there is an edge between i and j with
length of c,
if c=0,
then there isn't any edge between i and j.

The input data ensure that the i-th
number of the i-th
line is always 0, and the j-th
number of the i-th
line is always equal to the i-th
number of the j-th
line.
 
Output
For each test case, print a single line containing a single integer, denoting the answer modulo 109+7.
 
Sample Input
2
01
10
4
0123
1012
2101
3210
 
Sample Output
1
6
 
Source


——————————————————————————————————
题目的意思是给出一张图,求最短路数的个数有多少种
思路:求出最短路,在求最短路时记录到达每个点的方案数,结果就是所有点方案数之和

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional> using namespace std; #define LL long long
const int INF=0x3f3f3f3f;
const int mod=1e9+7; int n,m;
int mp[55][55];
int dis[55];
int vis[55];
LL cnt[55];
struct node
{
int id,val;
friend bool operator<(node a,node b)
{
return a.val>b.val;
}
}; void djstl(int o)
{
memset(dis,INF,sizeof dis);
memset(vis,0,sizeof vis);
memset(cnt,0,sizeof cnt);
node f,d;
f.id=o,f.val=0;
priority_queue<node>q;
q.push(f);
vis[o]=cnt[o]=1,dis[o]=0;
while(!q.empty())
{
f=q.top();
q.pop();
vis[f.id]=1;
for(int i=0; i<n; i++)
{
if(!vis[i]&&f.val+mp[f.id][i]<dis[i])
{
dis[i]=f.val+mp[f.id][i];
cnt[i]=1;
d.id=i;
d.val=dis[i];
q.push(d);
}
else if(!vis[i]&&f.val+mp[f.id][i]==dis[i])
{
cnt[i]++;
}
}
}
} int main()
{
char s[55];
while(~scanf("%d",&n))
{
memset(mp,INF,sizeof mp);
for(int i=0; i<n; i++)
{
scanf("%s",&s);
for(int j=0; j<n; j++)
if(s[j]!='0')
mp[i][j]=s[j]-'0';
} djstl(0);
LL ans=1;
for(int i=0; i<n; i++)
{
ans*=cnt[i];
ans%=mod;
}
printf("%d\n",ans);
}
return 0;
}

HDU6026 Deleting Edges 2017-05-07 19:30 38人阅读 评论(0) 收藏的更多相关文章

  1. ZOJ2208 To and Fro 2017-04-16 19:30 45人阅读 评论(0) 收藏

    To and Fro Time Limit: 2 Seconds      Memory Limit: 65536 KB Mo and Larry have devised a way of encr ...

  2. POJ3320 Jessica's Reading Problem 2017-05-25 19:55 38人阅读 评论(0) 收藏

    Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12346   Accep ...

  3. HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏

    Automatic Judge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  4. HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏

    Happy Necklace                                                                           Time Limit: ...

  5. HDU6029 Graph Theory 2017-05-07 19:04 40人阅读 评论(0) 收藏

    Graph Theory                                                                 Time Limit: 2000/1000 M ...

  6. HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏

    Easy Summation                                                             Time Limit: 2000/1000 MS ...

  7. Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏

    Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...

  8. 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏

    滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...

  9. 第十二届浙江省大学生程序设计大赛-Lunch Time 分类: 比赛 2015-06-26 14:30 5人阅读 评论(0) 收藏

    Lunch Time Time Limit: 2 Seconds Memory Limit: 65536 KB The 999th Zhejiang Provincial Collegiate Pro ...

随机推荐

  1. Java Magic. Part 4: sun.misc.Unsafe

    Java Magic. Part 4: sun.misc.Unsafe @(Base)[JDK, Unsafe, magic, 黑魔法] 转载请写明:原文地址 系列文章: -Java Magic. P ...

  2. session第二篇

    二 A.application对象 1.application对象实现了用户间数据的共享,可存放全局变量. 2.application对象开始于服务器的启动,终止于服务器的关闭. 3.在用户的前后连接 ...

  3. C#实现支持单点登录的一个存储用户信息的类

    网上有很多介绍单点登录的文章,但多为架构设计以及概念性文章,而本文将介绍单点登录的具体具体实现 利用哈希表,作为保存登录用户的队列        private static Hashtable m_ ...

  4. Oracle VM VirtualBox做好虚拟硬盘后,如何进一步修改虚拟硬盘的大小

    以管理员身份打开, 命令提示符窗口,然后利用命令cd进入Oracle VM VirtualBox安装目录,如下图: 我进入了Oracle VM VirtualBox安装目录:D:\Program Fi ...

  5. 协同过滤 spark scala

    1 http://www.cnblogs.com/charlesblc/p/6165201.html [转载]协同过滤 & Spark机器学习实战 2 基于Spark构建推荐引擎之一:基于物品 ...

  6. Spring依赖注入:注解注入

    注解注入顾名思义就是通过注解来实现注入, Spring和注入相关的常见注解有Autowired.Resource.Qualifier.Service.Controller.Repository.Com ...

  7. LibreOJ 6282 数列分块入门 6(在线插入在线查询)

    题解:还是分块,将每个块存入vector,然后在插入的时候就是sqrt(n)级的重构,如果块太大了,暴力将这个块拆开. 代码如下: #include<cmath> #include< ...

  8. Django的模板语言介绍

    模板语言: 1.我们先看下在命令行中渲染模板 先导入模块对象 2.渲染一个变量 <p>当前时间:{{ time }}</p> return render(request,&qu ...

  9. [leetcode]211. Add and Search Word - Data structure design添加查找单词 - 数据结构设计

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  10. JTemplate学习(三)

    另一种模板写法 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xh ...