山东省第7届ACM省赛 F题 Feed the monkey dp

傻逼记忆化搜索 可是比赛时候我没去敲 赛后1A什么的还是退坑的好

Feed the monkey

Time Limit: 2000MS Memory limit: 131072K

题目描述

Alice has a monkey, she must feed fruit to the monkey every day.She has three kinds of fruits, bananas, 
peaches and apples. Every day, she chooses one in three, and pick one of this to feed the monkey. 
But the monkey is picky, it doesn’t want bananas for more than D1 consecutive days, peaches for more than D2 
consecutive days, or apples for more than D3 consecutive days. Now Alice has N1 bananas, N2 peaches and N3 
apples, please help her calculate the number of schemes to feed the monkey.

输入

 Multiple test cases. The first line contains an integer T (T<=20), indicating the number of test case.
Each test case is a line containing 6 integers N1, N2, N3, D1, D2, D3 (N1, N2, N3, D1, D2, D3<=50).

输出

 One line per case. The number of schemes to feed the monkey during (N1+N2+N3) days.
The answer is too large so you should mod 1000000007.

示例输入

1
2 1 1 1 1 1

示例输出

6

提示

 Answers are BPBA, BPAB, BABP, BAPB, PBAB, and ABPB(B-banana P-peach A-apple)

来源

 “浪潮杯”山东省第七届ACM大学生程序设计竞赛

示例程序

ACcode:

#include <bits/stdc++.h>
#pragma warning(disable:4786)//使命名长度不受限制
#pragma comment(linker, "/STACK:102400000,102400000")//手工开栈
#define maxn 52
#define mod 1000000007
using namespace std;
int dp[maxn][maxn][maxn][3][maxn];
int A,B,C,a,b,c,sum;
inline int dfs(int x,int y,int z,int t,int n){
    if(x>A||y>B||z>C||x+y+z>sum)return 0;
    if(t==0&&n>a||t==1&&n>b||t==2&&n>c)return 0;
    if(dp[x][y][z][t][n]!=-1)return dp[x][y][z][t][n];
    if(x+y+z==sum)return 1;
    int ans=0;
    if(t==0){
        ans=(ans+dfs(x+1,y,z,0,n+1))%mod;
        ans=(ans+dfs(x,y+1,z,1,1))%mod;
        ans=(ans+dfs(x,y,z+1,2,1))%mod;
        return dp[x][y][z][t][n]=ans;
    }
    if(t==1){
        ans=(ans+dfs(x+1,y,z,0,1))%mod;
        ans=(ans+dfs(x,y+1,z,1,n+1))%mod;
        ans=(ans+dfs(x,y,z+1,2,1))%mod;
        return dp[x][y][z][t][n]=ans;
    }
    if(t==2){
        ans=(ans+dfs(x+1,y,z,0,1))%mod;
        ans=(ans+dfs(x,y+1,z,1,1))%mod;
        ans=(ans+dfs(x,y,z+1,2,n+1))%mod;
        return dp[x][y][z][t][n]=ans;
    }
}
int main(){
    int loop;
    scanf("%d",&loop);
    for(;loop--;){
        scanf("%d%d%d%d%d%d",&A,&B,&C,&a,&b,&c);
        sum=A+B+C;
        memset(dp,-1,sizeof(dp));
        int ans=0;
        ans=(ans+dfs(1,0,0,0,1))%mod;
        ans=(ans+dfs(0,1,0,1,1))%mod;
        ans=(ans+dfs(0,0,1,2,1))%mod;
        printf("%d\n",ans);
    }
    return 0;
}


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值