这道题目第二次看的时候才彻底理解了是什么意思

把题目转化为数学模型分析后就是 有一个初始序列, 有一个进化率矩阵

求的是初始序列 与进化率矩阵进行 m 次运算后, 初始序列最后一位的答案

那么显然,可以对进化率矩阵进行快速幂计算

Example

Let's assume that P(0, 1) = P(1, 2) = 1, and at the beginning of a sub-process, the populations of 0, 1, 2 are 40, 20 and 10 respectively, then at the end of the sub-process, the populations are 0, 40 and 30 respectively.

这个栗子看懂了这题就会懂了。

Source Code:

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = * ;
const ll P = 10000000097ll ; int n, m; struct Mat{
double mat[N][N];
}; Mat operator * (Mat a, Mat b){
Mat c;
memset(c.mat, , sizeof(c.mat));
for(int k = ; k < n; ++k){
for(int i = ; i < n; ++i){
if(a.mat[i][k] <= ) continue; //
for(int j = ; j < n; ++j){
if(b.mat[k][j] <= ) continue; //
c.mat[i][j] += a.mat[i][k] * b.mat[k][j];
}
}
}
return c;
} Mat operator ^ (Mat a, int k){
Mat c;
for(int i = ; i < n; ++i){
for(int j = ; j < n; ++j){
c.mat[i][j] = (i == j); //init
}
}
for(; k; k >>= ){
if(k & ) c = c * a; //key
a = a * a;
}
return c;
} int main(){
int i, j, t, k, u, v, numCase = ;
while(EOF != scanf("%d%d",&n,&m)){
if( == n && == m) break;
double val;
Mat a, b;
memset(a.mat, , sizeof(a.mat));
memset(b.mat, , sizeof(b.mat));
for(i = ; i < n; ++i) b.mat[i][i] = ;
for(i = ; i < n; ++i) scanf("%lf", &a.mat[i][i]);
scanf("%d",&t);
while(t--){
scanf("%d%d%lf",&u,&v,&val);
b.mat[u][u] -= val; //
b.mat[u][v] = val; //
}
b = b ^ m;
double cur = ;
for(i = ; i < n; ++i){
cur += b.mat[i][n - ] * a.mat[i][i];
}
/*
for(i = 0; i < n; ++i){
for(j = 0; j < n; ++j){
cout << c.mat[i][j] << ' ';
}
cout << endl;
}
*/
printf("%.0lf\n",cur);
}
return ;
} /*
3 1
40 20 10
2
0 1 1.0
1 2 1.0
*/

ZOJ 2853 Evolution 【简单矩阵快速幂】的更多相关文章

  1. HDU 1575 Tr A( 简单矩阵快速幂 )

    链接:传送门 思路:简单矩阵快速幂,算完 A^k 后再求一遍主对角线上的和取个模 /********************************************************** ...

  2. UVA10870—Recurrences(简单矩阵快速幂)

    题目链接:https://vjudge.net/problem/UVA-10870 题目意思: 给出a1,a2,a3,a4,a5………………ad,然后算下面这个递推式子,简单的矩阵快速幂,裸题,但是第 ...

  3. HDU 4990 Reading comprehension 简单矩阵快速幂

    Problem Description Read the program below carefully then answer the question.#pragma comment(linker ...

  4. Evolution(矩阵快速幂)zoj2853

    Evolution Time Limit: 5 Seconds      Memory Limit: 32768 KB Description Evolution is a long, long pr ...

  5. 简单矩阵快速幂(HDU Tr A 1575)

    题目中所给的方阵就是一个矩阵,而就是只要将题目所给矩阵不断进行相乘即可,本题中我采用的是直接重载运算符*,使矩阵每一个都进行运算,可以简化为只对对角线上的元素进行运算.最后所得结果就只需将最终的矩阵上 ...

  6. zoj2893 Evolution(矩阵快速幂)

    题意:就是说物种进化,有N种物种,编号是0——N-1,M次进化后,问你编号为N-1的物种有多少数量:其中要注意的就是i物种进化到j物种的概率是p:(那么剩下的不要忘了):所以单位矩阵初始化对角线的值为 ...

  7. Codeforces - 185A 简单矩阵快速幂

    题意:求第n个三角形内部的上三角形个数 对每个三角形分别维护上下三角形个数,记为\(dp[1][i],dp[2][i]\) 规律很明显是 \(dp[1][i+1]=3*dp[1][i]+dp[2][i ...

  8. hdu------(1757)A Simple Math Problem(简单矩阵快速幂)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. POJ3070矩阵快速幂简单题

    题意:       求斐波那契后四位,n <= 1,000,000,000. 思路:        简单矩阵快速幂,好久没刷矩阵题了,先找个最简单的练练手,总结下矩阵推理过程,其实比较简单,关键 ...

随机推荐

  1. A Byte of Python 笔记(9) 面向对象编程

    第11章  面向对象编程 面向过程:根据操作数据的函数或语句块来设计程序. 面向对象(OOP, object-oriented programming):把数据和功能结合起来,用对象包裹组织程序. 类 ...

  2. LintCode-删除元素

    题目描述: 给定一个数组和一个值,在原地删除与值相同的数字,返回新数组的长度. 元素的顺序可以改变,并且对新的数组不会有影响. 样例 给出一个数组 [0,4,4,0,0,2,4,4],和值 4 返回 ...

  3. IAR Embedded Workbench for ARM 6.50.6 & 6.60.1 破解补丁

    IAR EWARM 6.50.6 & 6.60.1 破解 破解原理和方法见:http://blog.csdn.net/chivalrys/article/details/8564568 IAR ...

  4. Python+django开发环境搭建

    Python目前主版本有2个,2.7+和3.4+ 新入手,决定还是从2.7开始 先从python官网https://www.python.org/下载python2.7.10,64位版本(这里注意,选 ...

  5. golang实现udp接入服务器

    前端通过udp与接入服务器连接,接入服务器与后端tcp服务器维持tcp连接.目录结构及后端tcp服务器代码同上一篇博客. main.go package main import ( "lot ...

  6. Linq to sql介绍及增、删、改、查

    LinQ是指集成化查询语言,通过映射将数据库内的表名变为C#的类名,将列名作为属性名,将表的关系作为类的成员对象.O--M--R O-Object对象 R-Relation关系 M-Mapping映射 ...

  7. VC++6.0打开文件出错的解决办法

    1.下载http://support.microsoft.com/kb/241396里面的一个叫FileTool.exe的文件并解压,解压后是一个vc工程,用vc6.0打开工程,编译,得到FileTo ...

  8. 学习validate

    jQuery Validate (转自http://www.w3cschool.cc/jquery/jquery-plugin-validate.html?utm_source=tuicool) jQ ...

  9. Java 使用Dom4j和JFileChooser实现xml文件的自主选择路径导出

    直接来个简单的例子,大家一看便知. Document doc=DocumentHelper.createDocument();//创建document Element rootElement=doc. ...

  10. BZOJ 1679: [Usaco2005 Jan]Moo Volume 牛的呼声( )

    一开始直接 O( n² ) 暴力..结果就 A 了... USACO 数据是有多弱 = = 先sort , 然后自己再YY一下就能想出来...具体看code --------------------- ...