"Tide Cup" Shandong province, the seventh session of ACM College students Program Design competition-Feed The Monkey (memory search) __contest

Source: Internet
Author: User

Link

Meaning

Give you the number of 3 kinds of fruit, and the maximum number of consecutive days to eat fruit. Ask you how many kinds of programs monkeys eat fruit.


Point:

Memory search, at the beginning (pre=-1) can eat 3 kinds of fruit, and then change to eat search is good.

0 0 0 is definitely 1.

Found only a kind of fruit, it is necessary to see if you can eat it all at once. Because the remaining fruit can be greater than the maximum number of consecutive days.

DP initialization cannot be 0, can be 1, and then pruned. Because the answer to 0 is quite a lot. So-1 is better, no timeout.

I opened the VIS array separately.


#include <iostream> #include <stdio.h> #include <queue> #include <vector> #include <string.h
> #include <algorithm> using namespace std;
#define LL Long, const LL mod=1000000007;
LL Dp[55][55][55][4];
LL d1,d2,d3;

int vis[55][55][55][4];
    ll Dfs (ll x,ll y,ll z,ll Pre) {ll num=0;
    LL k=0;
    if (x!=0) k=1,num++;
    if (y!=0) k=2,num++;
    if (z!=0) k=3,num++;
    if (num==0) return 1;
        if (num==1) {if (K==1&AMP;&AMP;X&LT;=D1) return 1;
        if (K==2&AMP;&AMP;Y&LT;=D2) return 1;
        if (K==3&AMP;&AMP;Z&LT;=D3) return 1;
    return 0;
    } if (Pre!=-1&&vis[x][y][z][pre]) return dp[x][y][z][pre];
    LL xx=min (X,D1);
    LL yy=min (Y,D2);
    LL zz=min (Z,D3);
    LL ans=0;
        if (pre==-1) {for (LL i=1;i<=xx;i++) {(Ans+=dfs (x-i,y,z,1))%=mod;
        for (LL i=1;i<=yy;i++) {(Ans+=dfs (x,y-i,z,2))%=mod; for (LL i=1;i<=zz;i++) {(Ans+=dfs (x,y,z-i,3))%=mod;
        } if (Pre==1) {for (LL i=1;i<=yy;i++) {(Ans+=dfs (x,y-i,z,2))%=mod;
        for (LL i=1;i<=zz;i++) {(Ans+=dfs (x,y,z-i,3))%=mod;
        } if (pre==2) {for (LL i=1;i<=xx;i++) {(Ans+=dfs (x-i,y,z,1))%=mod;
        for (LL i=1;i<=zz;i++) {(Ans+=dfs (x,y,z-i,3))%=mod;
        } if (pre==3) {for (LL i=1;i<=xx;i++) {(Ans+=dfs (x-i,y,z,1))%=mod;
        for (LL i=1;i<=yy;i++) {(Ans+=dfs (x,y-i,z,2))%=mod;
    } if (pre!=-1) dp[x][y][z][pre]=ans,vis[x][y][z][pre]=1;
return ans;
    int main () {LL T;
    scanf ("%lld", &t);
        while (t--) {LL n1,n2,n3;
        scanf ("%lld%lld%lld%lld%lld%lld", &n1,&n2,&n3,&d1,&d2,&d3);
                    for (int i=0;i<=n1;i++) for (int j=0;j<=n2;j++) for (int k=0;k<=n3;k++) For (inT t=0;t<=3;t++) vis[i][j][k][t]=0;
        
    Cout<<dfs (n1,n2,n3,-1) <<endl;
return 0; }

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.