栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3604 Tunnel Network

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3604 Tunnel Network

#include <cstdio>#include <cstring>#include <vector>#include <queue>#include <iostream>#include <string>#include <ctime>#include <algorithm>#include <cmath>#include <ctime>using namespace std;typedef long long LL;typedef double DB;typedef unsigned UINT;typedef unsigned long long ULL;typedef vector<int> VI;typedef vector<char> VC;typedef vector<string> VS;typedef vector<LL> VL;typedef vector<DB> VF;const int dx4[] = {-1, 0, 1, 0};const int dy4[] = {0, 1, 0, -1};const int dx8[] = {-1, 0, 1, 0 , -1 , -1 , 1 , 1};const int dy8[] = {0, 1, 0, -1 , -1 , 1 , -1 , 1};const int MOD = 1000000007;const int INF = 100000;const LL INFF = 1LL << 60;const DB EPS = 1e-9;const DB OO = 1e15;const DB PI = acos(-1.0); //M_PI;#define SZ(A) int(A.size())#define PB push_back#define ALL(A) A.begin(), A.end()#define CPY(A, B) memcpy(A, B, sizeof(A))#define max(a,b) (a)>(b)?(a):(b)#define min(a,b) (a)<(b)?(a):(b)#define maxn 150void PrintMsk(int MASK,int base,int nbit){for(int i=0;i<nbit;i++,MASK/=base)printf("%d ",MASK%base);printf("%c",10);}void Display(int* ARR,int LEFT,int RIGHT){for(int i=LEFT ; i<=RIGHT ; i++ )printf("%d ",ARR[i]);printf("%c",10);}struct matrix{int n; int a[25][25];void clear(){ memset(a,0,sizeof(a)); }void init(){ clear(); for(int i=1;i<=n;i++) a[i][i]=1; }matrix operator * (matrix b){matrix c; c.n=n;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){c.a[i][j]=0;for(int k=1;k<=n;k++) c.a[i][j]+=a[i][k]*b.a[k][j];}return c;}matrix operator + (matrix b){matrix c; c.n=n;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)c.a[i][j]=a[i][j]+b.a[i][j];return c;}};int n,s;LL Pow(LL num,int times){LL res=1;while (times){if (times&1)res = res*num % MOD;num = num*num % MOD;times >>= 1;}return res;}void solv(){if (s == n){printf("1n");return;}LL ans = (LL)s * Pow(n,n-1-s) % MOD;printf("%dn",(int)ans);}int main(){int cas;scanf("%d",&cas);while (cas--){scanf("%d%d",&n,&s);solv();}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/376815.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号