Python code example for constructing a graph using an adjacent matrix, python Matrix
Problem
How to use the list structure diagram
Method of the adjacent matrix
Python sample code
#! /Usr/bin/env python #-*-encoding: UTF-8-*-# author: LiYanwei # version: 0.1 # '''a --- B \ | |\| | c |/e --- d/if an edge exists between an undirected graph vertex, the value is 1, o
P3390 [TEMPLATE] rapid matrix power, p3390 MatrixBackground
Rapid matrix powerDescription
Given n * n matrix A, evaluate A ^ kInput/Output Format
Input Format:
The first line, n, k
The number of n rows from 2nd to n + 1. The number of j rows in I + 1 indicates the elements in column j of row I in the matrix.
Output F
HDU 4965 Fast Matrix Calculation (Matrix Fast power)HDU 4965 Fast Matrix Calculation
Question Link
Multiply the matrix by AxBxAxB... by nn, it can be changed to Ax (BxAxBxA ...) xB: returns nn-1 in the middle. In this way, a matrix in the middle is only 6x6, so that we can u
POJ 3233 Matrix Power Series (Matrix optimization)
Ask S [k] = A + A ^ 2 +... + A ^ k
Using the rapid power of A matrix, we can quickly obtain the k power of A matrix, but this question is A sum. If we still follow the original method, we will calculate k times, which is unacceptable in complexity.
We can construct A
The matrix multiplication is realized by programming, and the optimization method is considered when the matrix scale is large:
(1) The general solution:
Matrix multiplication, 3 for loops to fix
void Mul (int** Matrixa, int** matrixb, int** Matrixc)
{for
(int i = 0; i for (int j = 0; J (2) Strassen algorithm (block + divide-and-conquer idea):
Al
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 5015
Because it is a two-dimensional recursive formula, we didn't expect to construct a matrix like this. From the column, the current column is obtained by recursion of the previous column. Construct a matrix based on this point. B [I] represents column I, which is a matrix (n + 2) * 1, that is, B [1] = [1,233 ...
[BZOJ 2738] matrix multiplication and bzoj2738 Matrix Multiplication2738: Matrix Multiplication
Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 841 Solved: 351[Submit] [Status] [Discuss]Description
This gives you a N * N matrix, which does not involve matrix multiplication, b
HDU 3376 -- Matrix Again [maximum cost flow Classic Graph creation], hdu3376 -- matrix
Matrix Again
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Submission (s): 3457 Accepted Submission (s): 1020
Problem DescriptionStarvae very like play a number game in the n * n Matrix. A
HDU5015-233 Matrix (Matrix Rapid power), hdu5015-233matrix
Question Link
Given the number of 0th to n columns in a matrix, each number starts from 1st in the first row and is 1st ........, calculates the number of m in the nth row.
Train of Thought: shift the number of the first row to the right, and use the previous column to roll out the next column to constr
3240: [noi2013] matrix game time limit: 10 sec memory limit: 256 MB
Submit: 613 solved: 256
[Submit] [Status]
Description
Tingting is a matrix-loving child. One day she wants to use a computer to generate a huge N-Row M-column matrix (you don't have to worry about how she stores it ). The matrix she generated satisfi
Network, relationship and other data into the adjacency matrix (red represents two nodes is a person, there is a link between), but the resulting matrix will be due to the order of the problem of the different arrangement, in the first will find that because there is a clustered block area and easily divide the data into two parts, Then according to the specific meaning of the data to know the meaning of it
, if there is an remainder, you can simulate it in a few steps ). Note that any replacement can be expressed as a matrix. For example, replacing 1 2 3 4 with 3 1 2 4 is equivalent to the following matrix multiplication:Replacing K/M is equivalent to multiplying the k/M matrix. We can calculate the k/M power of the matrix
[Special statement] This article is purely my personal behavior. It is totally out of my preferences and has nothing to do with Turing.
However, it should be noted that writing this book review is entirely from the whim. Although I want to maintain neutral, I am a publisher, and the service provider can be said to be a competitor of the publishing house. Therefore, it is not a suitable reviewer, please pay special attention to this when reading the f
/** Matrix-browser * * Simple Web Viewer used by Matrix Application Launcher * * Copyright (C) 2011,2012 Texas Instrume NTS Incorporated-http://www.ti.com/ * * * redistribution and use in source and binary forms, with or without * modification, is permitted provided tha t the following conditions * is met: * * redistributions of source code must retain the above copyright * Notice , this list of conditions
This question is the third application of matrix multiplication. However, pleaseS=A+A2 +A3 +... +AK. The result matrix M67 Daniel's blog mentioned above is a sub-governance method. Set f [N] = a ^ 1 + a ^ 2 +... a ^ N;If n is an even number, F [N] = f [n/2] + F [n/2] * a ^ (n/2 );However, n is an odd number, and f [N] = f [n-1] + A ^ (N). After reading discuss, we found a method with lower programming compl
Difficulty, indeed, is not difficult
The problem is that there is a matrix operation optimization.
The question is to give matrix A of N * k to matrix B of K * n (1
Equivalent
Ababababababab... = (AB) ^ (N * n)
Worse
A (BA) ^ (N * N-1) B
Because the BA multiplied K * k matrix, K is relatively small.
#include
Matrix concatenation algorithm implemented by Ruby and ruby matrix concatenation
Dynamic Planning solves the problem of matrix concatenation, generates matrix sequences randomly, and outputs results in the form of (A1 (A2A3) (A4A5.
Code:
#encoding: utf-8=beginauthor: xu jin, 4100213date: Oct 28, 2012MatrixChainto find
HDU 4920 sparse matrix multiplication, hdu4920 Matrix Multiplication
Violent. Don't think too much.
T ^ T g is too bad
# Include
There is a program for the multiplication of sparse matrices, but I cannot explain it.
In the previous loop, the triple table storage will be restored to the normal operation by pressing the mark according to the matrix multiplica
HDU 2842 Chinese Rings (with constant matrix + rapid matrix power), hdu2842HDU 2842 Chinese Rings (with constant matrix + rapid matrix power)
ACM
Address: HDU 2842 Chinese Rings
Question:A Chinese ring, the k ring to be unlocked first needs to be unlocked before (K-2) a ring, and leave the (k-1) ring. It takes at least
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.