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. SQL语句查询年龄分段分组查询

    此情况用于数据库中没有“年龄”这个字段,只有“出生日期”这个字段.先计算出“年龄”,在分组查询. 1.SELECT *, ROUND(DATEDIFF(CURDATE(), popBirthday)/ ...

  2. 吴裕雄 数据挖掘与分析案例实战(5)——python数据可视化

    # 饼图的绘制# 导入第三方模块import matplotlibimport matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['S ...

  3. k8s 问题

    kubelet: Orphaned pod "4db449f0-4eaf-11e8-94ab-90b8d042b91a" found, but volume paths are s ...

  4. Group by 内部排序

    1.right join #  update_time  gid=>sid, group_status => s_table select a.* from comment as a ri ...

  5. zoj1004-Anagrams by Stack 【栈 dfs】

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4 Anagrams by Stack Time Limit: 2 Seconds ...

  6. Linux 线程调度

    1.线程sleep()后,会让出cpu的时间片,交由其他线程进行抢占cpu. 线程之间正常的切换是依靠时间片的. 当主线程没有结束,且其在所占有的时间片内,并没有结束自己的工作,此时,子线程将会抢占c ...

  7. OC 线程操作 - GCD快速迭代

    - (void)forDemo{ //全都是在主线程操作的 ; i<; i++) { NSLog(@"--%@", [NSThread currentThread]); } ...

  8. 开发中经典sql总结

    1.说明:显示文章.提交人和最后回复时间 select a.title,a.username,b.adddate ,(select max(adddate) from table where tabl ...

  9. 搭建Eureka集群

    1.pom文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...

  10. 一、消息队列之ActiveMQ的安装、配置和C#样例代码

    最近有时间了,研究一下消息队列ActvieMQ,结合自己的实践和网上的一些大家内容,整理如下,所有步骤和链接均是正确的. 1.ActiveMQ ActiveMQ 是Apache出品,最流行的,能力强劲 ...