首页 > 其他 > 详细

J Less taolu

时间:2019-01-06 19:41:14      阅读:162      评论:0      收藏:0      [点我收藏+]

链接:https://ac.nowcoder.com/acm/contest/338/J
来源:牛客网

题目描述


Less taolu, more sincerity.

This problem is very easy to solve.
You may be very tired during this contest. So we prepared a gift for you.

You just copy and paste this code and you will get AC!

Ctrl + C && Ctrl + V is a necessary skill for a programming ape.

#include<iostream>
using namespace std;
const long long mod = 1e9+7;
long long func(int x){
    if (x==1||x==0){
        return 1;
    }
    return (x*func(x-1)+(x-1)*func(x-2))%mod;
}
int n;
int main(){
    cin>>n;
    cout<<func(n);
    return 0;
}
 

 


输入描述:

Input only a single
integer n.

输出描述:

Please output
the answer by this code.
示例1

输入

复制
3

输出

复制
11
示例2

输入

复制
100

输出

复制
372497045

备注:

0<=N<=1e5

记忆化搜索,懒得解释

技术分享图片
#include<iostream>
using namespace std;
const int maxn = 100000+10;
int f[maxn];
const long long mod = 1e9+7;
long long func(int x)
{
    if (x==1||x==0)
    {
        return 1;
    }
    if(f[x])
        return f[x];
    else
        return f[x] = (x*func(x-1)+(x-1)*func(x-2))%mod;
}
int n;
int main()
{
    cin>>n;
    cout<<func(n);
    return 0;
}
View Code

 

J Less taolu

原文:https://www.cnblogs.com/DWVictor/p/10229930.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!