zoukankan      html  css  js  c++  java
  • 求m阶矩阵的n次幂

    题目如题

    直接上代码了。

     1 import java.util.Scanner;
     2 
     3 public class test
     4 {
     5     public static void main(String [] args)
     6     {
     7         int m,n,i,j,p;
     8         int array[][]=new int[100][100];
     9         int temp[][]=new int[100][100];
    10         Scanner scanner=new Scanner(System.in);
    11         System.out.printf("input m,n:");   //m表示矩阵的阶数,n表示的幂数
    12         m=scanner.nextInt();
    13         n=scanner.nextInt();
    14         System.out.printf("input the value of matrix 
    ");
    15         for(i=0;i<m;i++)    //输入矩阵
    16         {
    17             for(j=0;j<m;j++)
    18             {
    19                 array[i][j]=scanner.nextInt();
    20             }
    21         }
    22         for(i=0;i<m;i++)
    23         {
    24             for(j=0;j<m;j++)
    25             {
    26                for(p=0;p<m;p++)
    27                 temp[i][j]+=array[i][p]*array[p][j];
    28             }
    29         }
    30         
    31         System.out.printf("the mth power of matrix:
    ");
    32         for(i=0;i<m;i++)  //输出结果
    33         {
    34             for(j=0;j<m;j++)
    35             {
    36                 System.out.printf("%3d",temp[i][j]);
    37             }
    38             System.out.printf("
    ");
    39         }
    40     }
    41 }

    不解释。

  • 相关阅读:
    uoj35 后缀排序
    bzoj1026windy数
    poj2761 feed the dog
    codevs2875RY哥查字典
    bzoj1683[Usaco2005 Nov]City skyline 城市地平线
    codevs2464超级麻将
    初赛乱记
    让NOI Linux变得可用
    [HAOI2015] 按位或
    一句话CF
  • 原文地址:https://www.cnblogs.com/ttpn2981916/p/6592007.html
Copyright © 2011-2022 走看看