Fifth annual Blue Bridge Cup B/C + + undergraduate (real title trial) (9~10)

Source: Internet
Author: User
Tags bitset ming cmath

Nineth Maze Take treasure

Title: Underground Palace    X King 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"    input a line of 3 integers, separated by a space: N M K (1<=n,m<=50, 1<=k<=12)    Next has n rows of data, each line has M integer Ci (0<=ci<=12) The value of the treasure on behalf of this lattice    requires the output of an integer that represents the number of action plans that fetch the K-baby. The number may be large, outputting the result of its 1000000007 modulo. For example, input: 2 2 21 22 1 The program should output: 2 again for example, input: 2 3 21 2 32 1 5 The program should output: 14 Resource contract: Peak memory consumption < 256MCPU consumption  < 1000ms Please strictly according to the requirements of the output, do not be superfluous to print 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, do not invoke special functions that depend on the compilation environment or the 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.

This problem is a memory search, but if it's not me, then the problem data.

I can't read it anyway.

1 4 3
2 5 4 3

The obvious answer is 3.


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).


So obviously can take 2 5 4,2 5 3,2 4 3. But...... Online to find a test of AC, incredibly is 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 Long#define PI 3.141592654#define CLR (A, 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) (v). Begin (), (v). End () #define Acfun Std::ios::sync_with_stdio (False) #define SIZE (100000 + 1) #define MOD 1000000007using 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]&    gt;=0) return dp[x][y][_min+1][k];    int sum=0; if (x==n-1&&y==m-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;//walk through a lattice, if the value of the treasure in the grid than//xiaoming in the hands of any baby value is big, Xiao Ming can pick up it//to find out the TMP is the smallest incredibly WA. int tmp=_min;//if (_min==-1) tmp=g[x][y];//Sum+=dfs (x+xx[l],y+yy[l],tmp,k+1);/* For example 1 4 3 2 5 4 3 The answer is clearly 2 5 42 5 32 4 31 total three.            But the AC program actually answer is 0*//*//*/Sum+=dfs (x+xx[l],y+yy[l],g[x][y],k+1);        Sum%=mod;            }} else {for (l,0,2) {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%d%d", &n,&m,&kk)) {for (i,0,n) for (j,0,m) SF ("%d", &g[i        ][J]);        CLR (dp,-1);        int Ans=dfs (0,0,-1,0);    PF ("%d\n", ans); }}


The tenth question is more interesting. Until the pit is dead.

is to find the reverse order.

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


Long long ans uses LLD to output WA to cry. Change to I64d on AC ... Tired sleep does not love. It's a pit-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 Long#define PI 3.141592654#define CLR (A, 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) (v). Begin (), (v). End () #define Acfun Std::ios::sync_with_stdio (False) #define SIZE (100000 + 1) #define MOD 1000000007using 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 (a.val==b.val) return a.pos>b.pos;    Return a.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&LT;=QR) left=query (1,n,1);            Ql=l[i].pos+1,qr=n;            int right=0;            if (QL&LT;=QR) right=query (1,n,1);            Right=n-l[i].pos-right;            Ans+=f[left+right]; PF ("%d:%d%d\n ", l[i].val,left,right);        } PF ("%i64d\n", ans);    %LLD WA to death!!!! }}




Fifth annual Blue Bridge Cup B/C + + undergraduate (real title trial) (9~10)

Related Article

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.