A preliminary study on the memory algorithm for the case of the cave treasure hunt

Source: Internet
Author: User

//        //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:// -//        //        //Resource contract://Peak memory consumption < 256M//CPU Consumption < 1000ms//        //        //please strictly according to the requirements of the output, do not use the superfluous printing similar: "Please enter ..." Redundant content. //        //all the code is placed in the same source file, after debugging passed, the copy is submitted to the source. //        //Note: The main function needs to return 0//Note: Use only ANSI c/ansi C + + standards, and do not invoke special functions that depend on the compilation environment or operating system. //Note: All dependent functions must explicitly #include <xxx> in the source file, and the common header files cannot be omitted from the project settings. //        //when committing, be careful to choose the type of compiler you expect. #include<stdio.h>#include<string.h>//Define Map Size#defineSIZE 100#defineN 1000000007//Map ArraysintMap[size][size];//Memory Search Dataintrec[size][size][ -][ -];//Storing input dataintN, M, K;intFintXintYintCntintmax);intMain () {intI, J; scanf ("%d%d%d", &n, &m, &k);  for(i=1; i<=n; i++ )          for(j=1; j<=m; J + +) scanf ("%d", &Map[i][j]); //functions in <string.h> for memset initializationmemset (REC,0,sizeof(REC)); F (1,1,0,0); //Output Resultsprintf"%d", rec[1][1][0][0]); return 0;} //search function incoming x, y coordinates baby number in backpack baby max valueintFintXintYintCntintmax) {    //printf ("%d%d%d%d\n", x, Y, CNT, map[x][y]); //reach the end of the lower right corner    if(X==n && y==m) {//two types of eligible        if(cnt==k)returnRec[x][y][cnt][max] =1; Else if(cnt = k1&& Max <Map[x][y])returnRec[x][y][cnt][max] =1; Else            returnRec[x][y][cnt][max] =0; }        Long LongTMP =0; //can go down    if(x+1<=N) {if(Max <Map[x][y]) {tmp+ = f (x+1, Y, cnt+1, Map[x][y]); TMP%N; } tmp+ = f (x+1, Y, CNT, max); TMP%N; }        //you can go right.    if(y+1<=m) {if(Max <Map[x][y]) {tmp+ = f (x, y+1, cnt+1, Map[x][y]); TMP%N; } tmp+ = f (x, y+1, CNT, max); TMP%N; }    returnRec[x][y][cnt][max] =tmp; }

A preliminary study on the memory algorithm for the case of the cave treasure hunt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.