say it up front
Learning simplex
makes me experience it personally: read it a hundred times, and see its meaning
inner mmp
topic
BZOJ1061
Portal
solution
I'm too lazy to write the solution... (If I do, it's probably a long discussion, and me is too lazy to write...)
This question, according
to . The standard form of linear programming can be directly simplex
However, this complexity is really metaphysical. A pivot operation is 1e7 level = =? ? ?
The total number of operations is still non-guaranteed (non-polynomial)Can you get a card if you want a card?
I don't understand it very well...I also ask the big guy to advise
Regarding duality, you can take a look at the
2016 training team paper "On Linear Programming and Duality Problems - Dong Kefan"
Regarding the fully unimodular matrix, you can take a look at these two articles by Candy (I didn't understand it, I gave up)
Portal 1
Portal 2
For simplex learning materials, you can take a look at
fjzzq's blog
hrwhisper's blog
The following is the code that comes with a large constant
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
int N , M ;
double a[10005][1005] , eps = 1e-8 ;
int dcmp( double x ){ return x < -eps ? -1 : x > eps ; }
void pivot( int r , int c ){ // r is Basis
double tmp = - a[r][c] ; a[r][c] = -1 ;
register int j ;
for( j = 0 ; j <= N ; j ++ ) a[r][j] /= tmp ;
for( int i = 0 ; i <= M ; i ++ ){
if( dcmp( a[i][c] ) == 0 || i == r ) continue ;
tmp = a[i][c] ; a[i][c] = 0 ;
for( j = 0 ; j <= N ; j ++ )
a[i][j] += tmp * a[r][j] ;
}
}
void solve(){
while( true ){
int x = 0 , y = 0 ;
double rem = 1e15 ;
for( int i = 1 ; i <= N && !x ; i ++ )
if( a[0][i] > eps ) x = i ;
if( !x ) break ;
for( int i = 1 ; i <= M ; i ++ )
if( a[i][x] <-eps && rem > - a[i][0] / a[i][x] )
rem = - a[i][0] / a[i][x] , y = i ;
if( !y ) break ; // this will not happen
pivot( y , x ) ;
} printf( "%.0f" , a[0][0] ) ;
}
int main(){
scanf( "%d%d" , &N , &M ) ;
for( int i = 1 ; i <= N ; i ++ ) scanf( "%lf" , &a[0][i] ) ;
for( int i = 1 ; i <= M ; i ++ ){
int st , ed ;
scanf( "%d%d%lf" , &st , &ed , &a[i][0] ) ;
for( int j = st ; j <= ed ; j ++ ) a[i][j] = -1 ;
} solve() ;
}