lightoj1006【记忆化搜索(我是这么叫)】

搜索的时候记录一下,注意要long long;

#include<cstdio>
#include<queue>
#include<map>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL mod=1e9+7;
 
bool vis[10010];
LL ff[10010];
 
LL a, b, c, d, e, f;
LL fn(int n)
{
    if(vis[n])
        return ff[n]%10000007;
    vis[n]=1;
    return ff[n]=(fn(n-1)+fn(n-2)+fn(n-3)+fn(n-4)+fn(n-5)+fn(n-6))%10000007;
}
int main()
{
    int n, caseno = 0, cases;
    scanf("%d", &cases);
    while( cases-- )
    {
        scanf("%lld %lld %lld %lld %lld %lld %d", &ff[0], &ff[1], &ff[2], &ff[3], &ff[4], &ff[5], &n);
        memset(vis,false,sizeof(vis));
        for(int i=0;i<=5;i++)
            vis[i]=true;
        printf("Case %d: %lld\n", ++caseno,fn(n)%10000007);
    }
    return 0;
}


posted @ 2016-10-16 22:33  see_you_later  阅读(114)  评论(0编辑  收藏  举报