Found

Found
Time Limit: 10000ms, Special Time Limit:25000ms, Memory Limit:260144KB
Total submit users: 2, Accepted users: 2
Problem 13881 : No special judgement
Problem description
Alice and Bob live in a city with N intersections (numbered as intersection 1, intersection 2,…, intersection N). There are M roads. Each road is bidirectional and directly joins two intersections. Each pair of intersections is joined by at most one road.

Alice lives in a house at intersection 1. Bob lives in a house at intersection N. They start wandering in the city at 12pm. Each minute each one move from one intersection to another which is connected directly by a road. (Note that since they have to move, they cannot stay at the same intersection they were at in the previous minute).

They agree to meet exactly T minutes after 12pm at some intersection. Also they do not want to meet each other before T minutes. In how many ways can they move inside the city? Note that because they travel fairly fast, they do not meet if they travel on the same road on different directions. 


Input
The first line of the input contains an integer K (1<=K<=5), the number of test cases. Then K test cases follow in the format specified below.

Each test case starts with 3 integers N, M, and T (2<=N<=10; 1<=M<=50; 1<=T<=1,000,000,000,000). 
The next M lines specify road connections. That is, line 1+i, for 1<=i<=M, contain two integers A and B specifying that there is a bidirectional road connecting intersection A and B (1<=A<=N; 1<=B<=N; A is not equal to B).
Output
For each test case, your program should output the number of possible ways (modulo 9973) can Alice and Bob move in the city so that at time T they meet at some intersection but they do not meet at any intersection before that. Since the number can be very large, you should output the numbers modulo 9973.
Sample Input
4
3 3 2
1 2
2 3
1 3
3 2 2
1 2
2 3
4 4 10
1 2
2 4
1 3
4 3
4 5 1000
1 2
2 4
1 3
4 3
1 4
Sample Output
3
0
1024
3213
Problem Source
ACM-ICPC Asia Thailand National On-Site Programming Contest 2015

题解:n的范围很小,所以可以用a*n+b来表示a,b所在位置的状态,用mp[i][j]表示a,b能否从i状态转移到j状态,再进行矩阵快速幂(矩阵的k次乘方就相当于i经过k条路到达j的方数 当k=2时,∑ way[i][x] * way[x][j] (0<=x<n && x!=i && x!=j),以此类推

#include<iostream>
#include<algorithm> 
#include<string.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
const int mod=9973;
const int maxn=105;
bool mp[105][105];
int t,n,m;
ll T;
struct matrix{
    int m[105][105];
    friend matrix operator*(matrix a,matrix b){
        matrix c;
        for(int i=0;i<n*n;i++)
           for(int j=0;j<n*n;j++){
                  c.m[i][j]=0;
                  for(int k=0;k<n*n;k++)
                  c.m[i][j]+=a.m[i][k]*b.m[k][j]%mod;
                  c.m[i][j]%=mod;
           }
        return c;
    }
}cnt;
matrix qpow(matrix a,ll b){
    matrix ret;
    memset(ret.m,0,sizeof(ret.m));
    for(int i=0;i<n;i++) ret.m[i][i]=1;
    while(b){
        if(b&1) ret=ret*a;
        b>>=1;
        a=a*a;
    }
    return ret;
}
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d%d%I64d",&n,&m,&T);
        memset(mp,0,sizeof(mp));
        memset(cnt.m,0,sizeof(cnt.m));
        for(int u,v,i=0;i<m;i++){
            scanf("%d%d",&u,&v);
            mp[u][v]=mp[v][u]=1;
        } 
        for(int i=0;i<n*n;i++){
            int a=i/n+1,b=i%n+1;
            if(a==b) continue;
            for(int j=0;j<n*n;j++){
                int c=j/n+1,d=j%n+1;
                if(c==d||a==c||b==d||!mp[a][c]||!mp[b][d]) continue;
                cnt.m[i][j]=1;
            }
        }
        cnt=qpow(cnt,T-1);
        int ans=0;
        for(int i=0;i<n*n;i++){
            int a=i/n+1,b=i%n+1;
            if(!cnt.m[n-1][i]||a==b) continue;
            for(int j=1;j<=n;j++)
               if(mp[a][j]&&mp[b][j])
                  ans=(ans+cnt.m[n-1][i])%mod;
        }
        printf("%d\n",ans);
    }
}



### 解决 Maven Not Found 错误的方法 对于遇到 `Maven not found` 的情况,可以从多个角度来解决问题。具体取决于环境的不同以及具体的错误表现形式。 #### 更新 IDEA 中的仓库索引 当在 IntelliJ IDEA 中创建或导入 Maven 项目时,如果遇到依赖项无法解析的情况,可以尝试通过更新本地存储库索引来解决这个问题。这可以通过导航到菜单栏中的 **File->Settings** (或者在 macOS 上是 **IntelliJ IDEA->Preferences**),接着依次点击进入 **Build, Execution, Deployment -> Build Tools -> Maven -> Repositories** ,最后选择并执行刷新操作[^1]。 #### 修改 Gradle 插件应用语句 如果是基于 Gradle 构建工具而遇到了类似于 `'maven' plugin not found` 这样的警告,则可能是由于所使用的插件名称不正确引起的。应将构建脚本里的 `apply plugin: 'maven'` 更改为 `apply plugin: 'maven-publish'` 来适配最新版本的要求[^2]。 #### 安装 Homebrew 并设置环境变量 (针对 Mac 用户) 对于使用 M3 芯片 MacBook Pro 设备上的开发者来说,在终端运行命令时可能会碰到像 `zsh: command not found: brew` 这样表示找不到 Homebrew 工具的消息。这是因为系统的 shell 尚未配置好必要的路径所致。为了修正这一点,首先需要按照官方指南完成 Homebrew 的安装过程;之后再确认 `.zprofile` 或者其他启动文件里包含了指向 `/opt/homebrew/bin` 目录下的可执行文件的相关声明[^3]。 ```bash # 添加至 ~/.zprofile 文件末尾 export PATH="/opt/homebrew/bin:$PATH" ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值