Group B of the fifth Blue Bridge Cup C/C ++ undergraduate course (true question test) (9 ~ 10) Blue Bridge trial

Source: Internet
Author: User
Tags bitset

Group B of the fifth Blue Bridge Cup C/C ++ undergraduate course (true question test) (9 ~ 10) Blue Bridge trial

Question 9: treasure in the maze

Title: King X has a land palace treasure. Is a matrix of n x m grids. Put a piece of baby in each grid. Every baby is labeled with value. The entrance of the underground palace is in the upper left corner and the exit is in the lower right corner. James was taken to the entrance of the underground palace. The king asked him to walk only to the right or down. When walking through a grid, if the baby value in the grid is greater than any other baby value in Xiao Ming's hand, Xiao Ming can pick it up (or, of course, not take it ). When James arrives at the exit, if the baby in his hand happens to be k pieces, then these babies can be sent to James. Please help James calculate the number of different action plans he can get in a given situation. [Data format] Enter three integers in a row, separated by spaces: n m k (1 <= n, m <= 50, 1 <= k <= 12) next there are n rows of data, each row has m integer Ci (0 <= Ci <= 12) representing the value of the treasure on this grid requires an integer output, indicates the number of action plans that match k of babies. This number may be large and output the result of Modulo 1000000007. For example, the input: 2 2 21 22 1 program should output: 2. For example, the input: 2 3 21 2 32 1 5 program should output: 14 Resource conventions: peak memory consumption <256MCPU consumption <ms, please output strictly as required, do not print like: "Please input.... All codes are stored in the same source file. After debugging is successful, copy and submit the source code. Note: The main function must return 0. Note: Only the ansi c/ansi c ++ standard is used. Do not call special functions that depend on the compiling environment or operating system. Note: All dependent functions must be explicitly included in the source file # include <xxx>. Common header files cannot be omitted through engineering settings. When submitting, select the expected compiler type.

This question is memorized for search, but if it is not for me, the question data will be problematic.

I cannot understand it.

1 4 3
2 5 4 3

The answer is obviously 3.


When walking through a grid, if the baby value in the grid is greater than any other baby value in Xiao Ming's hand, Xiao Ming can pick it up (or, of course, not take it ).


Obviously, we can use 2 5, 4, 2 5, 3, 2, 4, 3. But ...... I found a test of an AC on the Internet, but it was actually 0.


# Include <cstdio> # include <cstring> # include <string> # include <queue> # include <algorithm> # include <map> # include <stack> # include <iostream> # include <list> # include <set> # include <bitset> # include <vector> # include <cmath> # define INF 0x7fffffff # define eps 1e-8 # define LL long # define PI 3.141592654 # define CLR (, b) memset (a, B, sizeof (a) # define FOR (I, a, B) for (int I = a; I <B; I ++) # define FOR _ (I, a, B) for (int I = a; I> = B; I --) # Define sf scanf # define pf printf # define all (v ). begin (), (v ). end () # define acfun std: ios: sync_with_stdio (false) # define SIZE (100000 + 1) # define MOD 1000000007 using namespace std; int dp [51] [51] [14] [13]; int g [51] [51]; int n, m, kk; int xx [] = {1, 0 }; int yy [] = {0, 1}; int dfs (int x, int y, int _ min, int k) {if (dp [x] [y] [_ min + 1] [k]> = 0) return dp [x] [y] [_ min + 1] [k]; int sum = 0; if (x = n-1 & y = s-1) {if (g [x] [y]> _ min ){ If (k = kk | k = kk-1) sum ++;} else if (k = kk) sum ++; return dp [x] [y] [_ min + 1] [k] = sum;} if (x = n | y = m) return 0; if (g [x] [y]> _ min) {FOR (l, 0, 2) {sum + = dfs (x + xx [l], y + yy [l], _ min, k); sum % = MOD; // if the value of the baby in a grid is greater than that of any baby in James, james can pick it up // find out that tmp is the smallest actually WA. // Int tmp = _ min; // if (_ min =-1) tmp = g [x] [y]; // sum + = dfs (x + xx [l], y + yy [l], tmp, k + 1 ); /* For example, the answer to 1 4 32 5 4 3 is obviously 2 5 42 5 32 4 3. However, the answer to the AC program is 0 * // */sum + = dfs (x + xx [l], y + yy [l], g [x] [y], k + 1); sum % = MOD ;}} else {FOR (l) {sum + = dfs (x + xx [l], y + yy [l], _ min, k); sum % = MOD ;}} return dp [x] [y] [_ min + 1] [k] = sum;} int main () {while (~ Sf ("% d", & n, & m, & kk) {FOR (I, 0, n) FOR (j, 0, m) sf ("% d", & g [I] [j]); CLR (dp,-1); int ans = dfs ); pf ("% d \ n", ans );}}


The tenth question is even more interesting. So far.

Is to find the reverse order.

The left side is bigger than it. The right side is smaller than it.


Long ans uses lld to output WA to cry. Change to I64d to AC... Tired. It's really a pitfall bridge cup.


# Include <cstdio> # include <cstring> # include <string> # include <queue> # include <algorithm> # include <map> # include <stack> # include <iostream> # include <list> # include <set> # include <bitset> # include <vector> # include <cmath> # define INF 0x7fffffff # define eps 1e-8 # define LL long # define PI 3.141592654 # define CLR (, b) memset (a, B, sizeof (a) # define FOR (I, a, B) for (int I = a; I <B; I ++) # define FOR _ (I, a, B) for (int I = a; I> = B; I --) # Define sf scanf # define pf printf # define all (v ). begin (), (v ). end () # define acfun std: ios: sync_with_stdio (false) # define SIZE (100000 + 1) # define MOD 1000000007 using namespace std; int t [SIZE * 3]; int us; void update (int l, int r, int o) {if (l = r) t [o] = 1; else {int m = (l + r)> 1; if (us <= m) update (l, m, o * 2); else update (m + 1, r, o * 2 + 1); t [o] = t [o * 2] + t [o * 2 + 1] ;}} int ql, qr; int query (int l, int r, int o) {if (ql <= l && Qr> = r) return t [o]; else {int m = (l + r)> 1; int ans = 0; if (ql <= m) ans + = query (l, m, o * 2); if (qr> m) ans + = query (m + 1, r, o * 2 + 1 ); return ans ;}} struct node {int pos, val; bool friend operator <(node a, node B) {if (. val = B. val) return. pos> B. pos; return. val> B. val ;}} l [SIZE]; LL f [SIZE * 10]; int main () {int n; f [0] = 0; FOR (I, 1, SIZE) f [I] = f [I-1] + I; while (~ Sf ("% d", & n) {CLR (t, 0); FOR (I, 1, n + 1) {sf ("% d ", & l [I]. val); l [I]. pos = I;} sort (l + 1, l + n + 1); LL ans = 0; FOR (I, 1, n + 1) {us = l [I]. pos; update (1, n, 1); ql = 1, qr = l [I]. pos-1; int left = 0; if (ql <= qr) left = query (1, n, 1); ql = l [I]. pos + 1, qr = n; int right = 0; if (ql <= qr) right = query (1, n, 1); right = n-l [I]. pos-right; ans + = f [left + right]; // pf ("% d: % d \ n", l [I]. val, left, right);} pf ("% I64d \ n", ans); // % lld WA to death !!!! }}




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.