Title: Underground Palace Take Treasure
King X has a underground palace treasure trove. is a matrix of n x M lattices. Put a baby in every grid. Each treasure is tagged with a value.
The entrance to the underground palace is in the upper left corner and exits in the lower right corner.
Xiaoming was taken to the entrance of underground palace, and the king demanded that he only walk right or down.
Walk through a lattice, if the treasure in the grid is worth more than Xiaoming's hand any treasure value is big, xiaoming can pick up it (of course, can not take).
When Xiao Ming walked to the exit, if the baby in his hand happens to be a k -piece, then these treasures can be given to xiaoming.
Please help Xiao Ming calculate, in a given situation, he has how many different ways of action to get this K - piece baby.
"Data Format"
Enter a line of 3 integers separated by spaces:N M K (1<=n,m<=50, 1<=k<=12)
Next there are n rows of data, each line having m integer Ci (0<=ci<=12) representing the value of the treasure on this lattice
An integer is required to indicate the number of action plans that fetch the K baby. The number may be large, outputting the result of its 1000000007 modulo .
For example, enter:
2 2 2
1 2
2 1
The program should output:
2
Again, for example, enter:
2 3 2
1 2 3
2 1 5
The program should output:
14
Resource contract:
Peak memory consumption < 256M
CPU consumption < 1000ms
Blue Bridge Cup Most of the questions can be done with DFS.
1#include <cstdio>2#include <cmath>3#include <algorithm>4#include <cstring>5 using namespacestd;6 intmap[ -][ -];7 intN, M, k, sum =0;8 intDFS (intXintYintBigintnowhave)9 {Ten if(Nowhave >k) One return 0; A if(x = = N && y = =m) - { - if(Nowhave = = k | | nowhave = = k-1&& Map[n][m] >big) thesum++; -Sum%=1000000007; - } - if(x +1<=N) + { - if(Map[x][y] >big) +DFS (x +1, Y, Map[x][y], Nowhave +1); ADFS (x +1, Y, big, nowhave); at } - if(Y +1<=m) - { - if(Map[x][y] >big) -DFS (x, y +1, Map[x][y], Nowhave +1); -DFS (x, y +1, big, nowhave); in } - } to intMain () + { -scanf"%d%d%d", &n, &m, &k); the for(inti =1; I <= N; i++) * for(intj =1; J <= M; J + +) $scanf"%d", &map[i][j]);Panax NotoginsengDFS (1,1,0,0); -printf"%d", sum); the return 0; +}
2014 Blue Bridge Cup--underground palace take Treasure