Please register or log in.
Item details add to favorites
Category Trucks, Tow vehicles
Created 2013-12-18
Owner kjlerydckd
Title ugg
Description Subject to the effect: given n, k, <a href="http://www.monclerdunjackasverige.se/">Moncler Jackor</a> and n * n is given a map from (1,1) through down the left and the right in three directions, go to (n, n) points, not to go the same way position, and the position of passing a negative number <= k, find your way out so that the value of this road and the maximum. Output impossible not reach


solving ideas: the memory of the search, with the four-dimensional array to record the optimal solution, vis-dimensional array represents the current access status, dp [x] [y] [i] [j] represents the position x, y place when passing The negative number is i and enter from the direction of the optimal solution when representatives of j.


timeout when I finished, but it changed direction a bit over the estimated direction of the reason is the optimal solution recorded live, so optimization is relatively large.


# include <stdio.h> # include <string.h> const int N = 80; const int MAX = -200000000; const int dir [3] [2] = {{0, -1}, {0, 1 }, {1, 0}}; int n, k, vis [N] [N], g [N] [N]; long long dp [N] [N] [10] [5], ans; void init () {ans = MAX; memset (vis, 0, sizeof (vis)); for (int i = 1; i <= n; i + +) for (int j = 1; j <= n; j + +) for (int x = 0; x <6; x + +) for (int y = 0; y <3; y + +) dp [i] [j] [x] [y] = MAX; for (int i = 1; i <= n ; i + +) for (int j = 1; j <= n; j + +) scanf ("% d", \x26amp; g [i] [j]);} void dfs (int x, int y, int cnt, long long sum) {if (cnt> k) return; if (x == <a href="http://www.monclerwinterjassenoutlet.nl/">Moncler Winterjassen</a> n \x26amp;\x26amp; y == n) <a href="http://www.monclerdunjackasverige.se/">Moncler Sverige</a> {if (sum> ans) ans = sum; return;} for (int i = 0; i <3; i + +) {int p = x + dir [i] [0]; int q = y + dir [i] [1]; if (p> 0 \x26amp;\x26amp; p <= n \x26amp;\x26amp; q> 0 \x26amp;\x26amp; q <= n \x26amp;\x26amp; vis [p] [ q] == 0) {vis [p] [q] = 1; if (g [p] [q] <0 \x26amp;\x26amp; dp [p] [q] [cnt + 1] [i] <sum + g [p ] [q]) {dp [p] [q] [cnt + 1] [i] = sum + g [p] [q]; dfs (p, q, cnt + 1, sum + g [p] [q ]);} else if (g [p] [q]> = 0 \x26amp;\x26amp; dp [p] [q] [cnt] [i] <sum + g [p] [q]) {dp [p] [q] [cnt] [i] = sum + g [p] [q]; dfs (p, q, cnt, sum + g [p] [q]);} vis [p] [q] = 0;}}} int main () {int t = 1; while (scanf ("% d% d", \x26amp; n, \x26amp; k) == 2 \x26amp;\x26amp; (nk)) {init (); vis [1] [1] = 1; if ( g [1] [1]> = 0) dfs (1, 1, 0, g [1] [1]); elsedfs (1, 1, 1, g [1] [1]); printf ("Case% d: ", t + +); if (ans = MAX) printf (!"% lld \\ n ", ans); elseprintf (" impossible \\ n ");} return 0;}