第四专题 Problem J

Problem Description
Jimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he likes to walk home. To make things even nicer, his office is on one side of a forest, and his house is on the other. A nice walk through the forest, seeing the birds and chipmunks is quite enjoyable. <br>The forest is beautiful, and Jimmy wants to take a different route everyday. He also wants to get home before dark, so he always takes a path to make progress towards his house. He considers taking a path from A to B to be progress if there exists a route from B to his home that is shorter than any possible route from A. Calculate how many different routes through the forest Jimmy might take. <br>
 

Input
Input contains several test cases followed by a line containing 0. Jimmy has numbered each intersection or joining of paths starting with 1. His office is numbered 1, and his house is numbered 2. The first line of each test case gives the number of intersections N, 1 < N ≤ 1000, and the number of paths M. The following M lines each contain a pair of intersections a b and an integer distance 1 ≤ d ≤ 1000000 indicating a path of length d between intersection a and a different intersection b. Jimmy may walk a path any direction he chooses. There is at most one path between any pair of intersections. <br>
 

Output
For each test case, output a single integer indicating the number of different routes through the forest. You may assume that this number does not exceed 2147483647<br>
 

Sample Input
  
  
5 6 1 3 2 1 4 2 3 4 3 1 5 12 4 2 34 5 2 24 7 8 1 3 1 1 4 1 3 7 1 7 4 1 7 5 1 6 7 1 5 2 1 6 2 1 0
 

Sample Output
  
  
2 4



思路:

用spfa求出2到各个点之间的距离,然后从1找出有多少条可以到2的点。同时用到了深搜


源码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
const int M = 1007;
const int INF = 0x3f3f3f3f;
using namespace std;

int map[M][M], d[M], ans[M];
int n, m;
bool vis[M];

void spfa(int u){
    for(int i = 1; i <= n; ++ i){
        d[i] = INF; vis[i] = 0;
    }
    vis[u] = 1; d[u] = 0;
    queue<int > q;
    q.push(u);
    while(!q.empty()){
        int temp = q.front(); q.pop(); vis[temp] = 0;
        for(int i = 1; i <= n; ++ i){
            if(d[i] > d[temp]+map[temp][i]){
                d[i] = d[temp]+map[temp][i];
                if(!vis[i]){
                    vis[i] = 1;
                    q.push(i);
                }
            }
        }
    }
}

int dfs(int u){
    if(ans[u] != -1) return ans[u];
    if(u == 2) return 1;
    ans[u] = 0;
    for(int i = 1; i <= n; ++ i){
        if(map[u][i] != INF&&d[i] < d[u]){
            ans[u] += dfs(i);
        }
    }
    return ans[u];
}

int main(){
    while(scanf("%d", &n), n){
        scanf("%d", &m);
        for(int i = 0; i <= n; ++ i){
            for(int j = 0; j <= n; ++ j){
                map[i][j] = (i == j?0:INF);
            }
        }
        int a, b, c;
        for(int i = 0; i < m; ++ i){
            scanf("%d%d%d", &a, &b, &c);
            map[a][b] = map[b][a] = min(c, map[a][b]);
        }
        spfa(2);
        memset(ans, -1, sizeof(ans));
        printf("%d\n", dfs(1));
    }
}

《现代量子力学问题的解决方法,第二版 J.J. Sakurai》是一本讲解现代量子力学问题解法的经典教材。以下是几个关于现代量子力学问题解决方法的主要方案: 1. 即时解决矩阵力学问题:矩阵力学是现代量子力学的一个重要分支,它涉及到矩阵算符的使用和计算。这本书提供了一套基于矩阵力学来解决问题的方法,包括如何构建哈密顿算符、求解本征值和本征函数等。 2. 利用路径积分方法解决量子力学问题:路径积分方法是解决量子力学问题的另一种重要方法。它以路径的形式描述了量子系统的演化,通过对路径的积分来计算物理量。这本书介绍了路径积分方法的基本原理和应用,如何通过路径积分计算系统的振幅和期望值。 3. 近似和穷尽解法:在现代量子力学中,很多问题无法严格求解,因此需要采用近似和穷尽解法。这本书提供了一些常见的近似方法,如微扰理论、变分法和平均场理论,可以帮助读者解决实际问题。 4. 引入相对论和场论:相对论和场论是现代量子力学的重要扩展,可以用于描述高能物理和粒子物理现象,如量子电动力学和量子色动力学等。这本书还介绍了相对论和场论的基本概念和解法,为读者进一步研究提供了基础。 总之,这本书以详细而全面的方式介绍了现代量子力学问题解决方法,涵盖了矩阵力学、路径积分方法、近似和穷尽解法以及相对论和场论等多个方面。通过学习这些方法,读者能够更好地理解和解决现代量子力学中的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值