Title Description Description
The game on a board with a 10*10 lattice, the initial pieces in the upper left corner, the end point is the lower right corner, the chessboard of each lattice has a number 0 to 9, each time a pawn can move to the right or lower adjacent lattice, to find a number and the smallest and through the 0 to 9 of all the number of the legal path, Output its length. (The number passed includes the upper-left and lower-right corners)
Enter a description input Description
The input consists of 10 rows, 10 digits per line, separated by a space, indicating the weight on the checkerboard lattice. The data guarantees the existence of a legitimate path.
outputs description output Description
Outputs the weights and values of the path you are seeking.
sample input to sample
0 1 2 3 4 5 6 7 8 9
1 1 1 1 1 1 1 1 1 0
2 1 1 1 1 1 1 1 1 0
3 1 1 1 1 1 1 1 1 0
4 1 1 1 1 1 1 1 1 0
5 1 1 1 1 1 1 1 1 0
6 1 1 1 1 1 1 1 1 0
7 1 1 1 1 1 1 1 1 0
8 1 1 1 1 1 1 1 1 0
9 1 1 1 1 1 1 1 1 5
Sample output Sample outputs
50
Sample explanation
Always go right to the end of the first line, and then go straight down to the optimal path.
Positive solution: Pressure DP
Problem Solving Report:
Recently nothing to do, brush point-like pressure DP water problem.
F[i][j][s] Record Arrival (I,J) when the state is the best answer, it is clear that 0 to 9 whether to go through the pressure into the binary. The complexity is correct.
Take note of the transition. This dimension should be in the innermost layer, the beginning of the sample has not been, only to find that the state must be in the innermost ...
1 //It's made by jump~2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <algorithm>8#include <ctime>9#include <vector>Ten#include <queue> One#include <map> A#include <Set> - #ifdef WIN32 - #defineOT "%i64d" the #else - #defineOT "%lld" - #endif - using namespacestd; +typedefLong LongLL; - Const intMAXN = A; + Const intMaxs = (1<< A); A intN; at intA[MAXN][MAXN]; - intF[MAXN][MAXN][MAXS]; - -InlineintGetint () - { - intw=0, q=0; in CharC=GetChar (); - while((c<'0'|| C>'9') && c!='-') c=GetChar (); to if(c=='-') q=1, c=GetChar (); + while(c>='0'&& c<='9') w=w*Ten+c-'0', c=GetChar (); - returnQ? -w:w; the } * $Inlinevoidsolve () {Panax Notoginsengn=Ten; Memset (F,127/3,sizeof(f)); - for(intI=1; i<=n;i++) the for(intj=1; j<=n;j++) +a[i][j]=getint (); A intEnd= (1<<n)-1; thef[1][1][1<<a[1][1]]=a[1][1]; + //cannot be placed as 0!!!!!! Only starting from 1 - $ //for (int i=1;i<=n;i++) $ //for (int j=1;j<=n;j++) - //f[i][j][0]=0; - the for(intj=1; j<=n;j++) - for(intk=1; k<=n;k++) {Wuyi if(j==1&& k==1)Continue; the for(intI=1; i<=end;i++) { - if((1<<A[J][K] | i)!=i)Continue; Wu intLin= (1<< -); -Lin=min (f[j-1][k][i],f[j][k-1][i]); AboutLin=min (Lin,min (f[j-1][k][i-(1<<A[J][K])],f[j][k-1][i-(1<<A[j][k] )); $f[j][k][i]=lin+A[j][k]; - } - } -printf"%d", F[n][n][end]); A } + the intMain () - { $ solve (); the return 0; the}
codevs1358 board Game