/*

第一次写的时候,因为没有注意导致栈溢出

zoj 的这个关于矩阵的题目让我感觉自己对矩阵还不是很了解,感觉这个变形让人很想不到的

做了这么多算是把矩阵这个内容掌握了,接下。。。

*/

#include <iostream>//2231603 2010-07-19 18:35:02 Accepted 2853 C++ 4460 840 悔惜晟

#include <cstdio>

#include <cstring>

using namespace std;

const int N = 205;//double  表示8位 小心超内存

typedef struct node

{

double  num[N][N];

}Mat;

Mat init, unit;

/*

Mat mal(Mat a, Mat b, int n)

{

Mat r;

for(int i = 0; i < n; i++)

for(int j = 0; j < n; j++)

r.num[i][j] = 0;

for(int i = 0; i < n; i++)

for(int k = 0; k < n; k++)

{

if(a.num[i][k])

for(int j = 0; j < n; j++)

if(b.num[k][j])

r.num[i][j] = (r.num[i][j] + a.num[i][k] * b.num[k][j]);

}

return r;

}

*/

void mul(int m, int n)

{

Mat r;

for(int i = 0; i < n; i++)

for(int j = 0; j < n; j++)

r.num[i][j] = 0;

while(m)

{

if(m & 1)

{

for(int i = 0; i < n; i++)

for(int j = 0; j < n; j++)

r.num[i][j] = 0;

for(int i = 0; i < n; i++)

for(int k = 0; k < n; k++)

{

if(unit.num[i][k])

for(int j = 0; j < n; j++)

if(init.num[k][j])

r.num[i][j] = (r.num[i][j] + unit.num[i][k] * init.num[k][j]);

}

m--;

unit = r;

}

else

{

for(int i = 0; i < n; i++)

for(int j = 0; j < n; j++)

r.num[i][j] = 0;

for(int i = 0; i < n; i++)

for(int k = 0; k < n; k++)

{

if(init.num[i][k])

for(int j = 0; j < n; j++)

if(init.num[k][j])

r.num[i][j] = (r.num[i][j] + init.num[i][k] * init.num[k][j]);

}

init = r;

m >>= 1;

}

}

}

int main()

{

int n, m;

while(scanf("%d %d", &n, &m) != EOF)

{

if(n == 0 && m == 0 )

break;

double data[N];

for(int i = 0; i < n; i++)

scanf("%lf", &data[i]);

int t;

int x, y;

double p;

for(int i = 0; i < n; i++)

for(int j = 0; j < n; j++)

{

init.num[i][j] = (i == j);//相当于init刚开始默认全部由自己进化到自己

unit.num[i][j] = (i == j);

}

scanf("%d", &t);

while(t--)

{

scanf("%d %d %lf", &x, &y, &p);

//init.num[y][x] += p;

init.num[x][y] += p;

init.num[x][x] -= p;

}

mul( m, n);

double sum = 0;

for(int i = 0; i < n; i++)

{

//sum += unit.num[n - 1][i] * data[i];

sum += unit.num[i][n - 1] * data[i];

}

printf("%0.0lf/n", sum);

}

}

http://www.cnblogs.com/forever4444/archive/2009/05/14/1456595.html

Evolution


Time Limit: 5 Seconds       Memory Limit: 32768 KB


Evolution is a long, long process with extreme complexity and involves many species. Dr. C. P. Lottery is currently investigating a simplified model of evolution: consider that we have N (2 <= N <= 200) species in the whole process of evolution, indexed from 0 to N -1, and there is exactly one ultimate species indexed as N-1. In addition, Dr. Lottery divides the whole evolution process into M (2 <= M <= 100000) sub-processes. Dr. Lottery also gives an 'evolution rate' P(i, j) for 2 species i and j, where i and j are not the same, which means that in an evolution sub-process, P(i, j) of the population of species i will transform to species j, while the other part remains unchanged.

Given the initial population of all species, write a program for Dr. Lottery to determine the population of the ultimate species after the evolution process. Round your final result to an integer.

Input

The input contains multiple test cases!

Each test case begins with a line with two integers NM. After that, there will be a line with N numbers, indicating the initial population of each species, then there will be a number T and T lines follow, each line is in format "i j P(i,j)" (0 <= P(i,j) <=1).

A line with N = 0 and M = 0 signals the end of the input, which should not be proceed.

Output

For each test case, output the rounded-to-integer population of the ultimate species after the whole evolution process. Write your answer to each test case in a single line.

Notes

  • There will be no 'circle's in the evolution process.
  • E.g. for each species i, there will never be a path i, s1, s2, ..., st, i, such that P(i,s1) <> 0, P(sx,sx+1) <> 0 and P(st, i) <> 0.
  • The initial population of each species will not exceed 100,000,000.
  • There're totally about 5 large (N >= 150) test cases in the input.

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.

Sample Input

2 3
100 20
1
0 1 1.0
4 100
1000 2000 3000 0
3
0 1 0.19
1 2 0.05
0 2 0.67
0 0

Sample Output

120
0

zoj 2853 Evolution相关推荐

  1. ZOJ 2853 Evolution[ 矩阵快速幂 ]

    传送门:ZOJ 1853 Description Evolution is a long, long process with extreme complexity and involves many ...

  2. 【学习笔记】线性代数全家桶(在编程竞赛中的应用)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 0x00. 矩阵 0x01. 矩阵 0x02. 矩阵的加法与数量乘法 0x03. 矩阵乘法 0x ...

  3. 矩阵快速幂 学习笔记

    据说,矩阵快速幂在递推式优化上相当神奇,而且效率很高... 两矩阵相乘,朴素算法的复杂度是O(N^3).如果求一次矩阵的M次幂,按朴素的写法就是O(N^3*M).既然是求幂,不免想到快速幂取模的算法, ...

  4. 【转载】图论 500题——主要为hdu/poj/zoj

    转自--http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  5. EyeQ进展The Evolution of EyeQ

    EyeQ进展The Evolution of EyeQ Mobileye's proven leadership in ADAS technologies is based in our EyeQ® ...

  6. ZOJ 2723 Semi-Prime ||ZOJ 2060 Fibonacci Again 水水水!

    两题水题: 1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数. 2.定义F(0) = 7, F(1) = 11, F(n) = F( ...

  7. zoj 1204 Additive equations

    ACCEPT acm作业 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=204 因为老师是在集合那里要我们做这道题.所以我很是天 ...

  8. 【HDU/POJ/ZOJ】Calling Extraterrestrial Intelligence Again (素数打表模板)

    http://poj.org/problem?id=1411  POJ http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=168 ...

  9. evolution ubuntu邮箱_Ubuntu下使用Evolution电子邮箱客户端

    =摘要= 话说一直是使用web的邮箱客户端,今天想了想应该试试Evolution这个linux下面的邮箱客户端.搞了搞,能够正常收发邮件了呵呵,在能够接收邮件的同时,现在也不用每一次都得登录到web邮 ...

最新文章

  1. 拿什么来拯救你,我的table
  2. Android --- 解决 cannot connect to daemon at tcp:5037: cannot connect to 127.0.0.1:5037: 由于目标计算机积极拒绝,无
  3. 爱上MVC~业务层刻意抛出异常,全局异常的捕获它并按格式返回
  4. GameMap其他初始化
  5. echo输出不重复行到文件 shell_Shell脚本echo指令使用小技巧
  6. 浅谈React Hooks
  7. java展开式的菜单_ListView点击Item展开菜单实现代码详解
  8. GPU图形绘制管线简介
  9. java strtus2 DynamicMethodInvocation配置(二)
  10. 采用分治法求一个整数序列中的最大和最小元素
  11. 【Pandas】北理工嵩天老师Python数据分析与展示之Pandas
  12. 数字IC设计入门(9)初识数字芯片验证
  13. linux防火墙关了连不上,SecrueCRT连接linux需要关闭linux防火墙_Centos 6.4 iptables防火墙关闭启动详解...
  14. Python OS模块和文件处理
  15. 安阳工学院计算机专业宿舍,安阳工学院宿舍条件,宿舍环境图片(10篇)
  16. 数字如潮人如水:在这个时代,你是要当算法,还是当数据?
  17. spss实现时间序列分析过程
  18. 【异常检测-论文阅读】(CVPR 2022)Self-Supervised Predictive Convolutional Attentive Block for Anomaly Detection
  19. caffe python 图片训练识别 实例
  20. PPT:智能仓储系统规划实战

热门文章

  1. 清华大学交叉信息研究院和计算机系,清华大学交叉信息研究院和量子信息中心揭牌成立...
  2. 爬虫+数据库+大数据分析
  3. Ubuntu下tar.gz文件安装方法
  4. 电芯容量在前期循环中容量增加_知荐 | 关于电芯正负极容量匹配设计的一些观点...
  5. python爬虫好友聊天记录_利用Python网络爬虫抓取微信好友的签名及其可视化展示...
  6. 强制员工五一加班 中青宝董事长李瑞杰辞职:94年儿子接任
  7. vue项目中可使用天气预报小组件推荐vue-mini-weather
  8. python实现网络测速
  9. 计算机操作员职业资格证书考试,国家职业资格计算机操作员考试指引.DOC
  10. dns nsswitch.conf