HTTP://CODEVS.CN/PROBLEM/1043/(Topic link)
Test instructions
N*n squares, each of which has a number, looks for the number of channels from (N,n) to the two paths that make up the channel and the maximum.
Solution
Water problem, ${f[i][j][k][l]}$ said one way to go (I,J), the other road to (K,L), take the largest number.
Code
codevs1043#include<algorithm> #include <iostream> #include <cstring> #include <cstdlib># include<cstdio> #include <cmath> #include <queue> #define LL long long#define inf 2147483640#define MOD 10000#define Pi ACOs ( -1.0) #define FREE (a) freopen (a ".", "R", stdin), Freopen (a ". Out", "w", stdout), using namespace std; const int Maxn=20;int a[maxn][maxn],f[maxn][maxn][maxn][maxn],n,m;int Main () {scanf ("%d", &n); int U,v,w;while ( scanf ("%d", &u)!=eof && u) {scanf ("%d%d", &v,&w); a[u][v]=w;} for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) for (int k=1;k<=n;k++) for (int l=1;l<=n;l++) {F[i][j][k][l]=max (Max (F[i-1][j][k-1][l],f[i-1][j][k][l-1]), Max (F[I][J-1][K-1][L],F[I][J-1][K][L-1)) +a[i][j]+a[k][l];if (i==k && j==l) f[i][j][k][l]-=a[i][j];} printf ("%d", F[n][n][n][n]); return 0;}
Number of "codevs1043" squares