表示我这种蒟蒻面对这种递推第一思想显然是打表啊

先贴个用来打表的暴力:

#include <cstdio>
struct node
{
    int l,r;
}p[];
bool used[];
int f[];
int n,cnt,cct;
int findf(int x)
{
    if(x==f[x])
    {
        return x;
    }
    return f[x]=findf(f[x]);
}
bool check()
{
    for(int i=;i<=n+;i++)
    {
        f[i]=i;
    }
    for(int i=;i<=cct;i++)
    {
        if(used[i])
        {
            int f1=findf(p[i].l);
            int f2=findf(p[i].r);
            f[f2]=f1;
        }
    }
    int ff=;
    for(int i=;i<=n+;i++)
    {
        int f1=findf(i);
        if(!ff)
        {
            ff=f1;
        }else if(ff!=f1)
        {
            return ;
        }
    }
    return ;
}
void dfs(int dep,int tot)
{
    if(dep==cct+)
    {
        if(tot==n)
        {
            if(check())
            {
                cnt++;
            }
        }
        return;
    }
    used[dep]=;
    dfs(dep+,tot+);
    used[dep]=;
    dfs(dep+,tot);
}
int main()
{
    scanf("%d",&n);    
    for(int i=;i<=n+;i++)
    {
        p[++cct].l=;
        p[cct].r=i;    
    }
    for(int i=;i<=n+;i++)
    {
        if(i==n+)
        {
            p[++cct].l=i;
            p[cct].r=;
        }else
        {
            p[++cct].l=i;
            p[cct].r=i+;
        }
    }
    dfs(,);
    printf("%d\n",cnt);
    return ;
}
/*
1 1
2 5
3 16
4 45
5 121
6 320
*/

实测这个打表程序是正确的(可以获得30分)

接下来是本人心路历程:

观察一下:1-1,2-5,3-16,4-45...找一下前后项吧!

观察前后项的倍数关系应该在2~3之间,那先定一个基础表达式

f[i]=2f[i-1]+...或f[i]=3f[i-1]+...

如果系数用2,发现剩下的部分长这样啊...

f[3]=2f[2]+6

f[4]=2f[3]+13

f[5]=2f[4]+31

...

好像后面的没啥规律...

那换系数用3!

f[4]=3f[3]-3

f[5]=3f[4]-14

...

好像也没啥啊...

等一下!

-3=-5+2

-14=-16+2

如果下面再写下来,应该是-43=-45+2!

这不就找出来了吗!

f[i]=3f[i-1]-f[i-2]+2!

于是敲个高精度这题就结束了...

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
struct Bignum
{
int a[10005];
int ilen;
}f[105],zero;
int n;
Bignum add(Bignum x)
{
Bignum ret=x;
ret.a[1]+=2;
int i=1;
while(ret.a[i]>=10)
{
ret.a[i+1]+=ret.a[i]/10;
ret.a[i]%=10;
i++;
}
if(ret.a[ret.ilen+1])
{
ret.ilen++;
}
return ret;
}
Bignum mul(Bignum x)
{
Bignum ret=zero;
for(int i=1;i<=x.ilen;i++)
{
ret.a[i]+=3*x.a[i];
ret.a[i+1]+=ret.a[i]/10;
ret.a[i]%=10;
}
ret.ilen=x.ilen;
while(ret.a[ret.ilen+1])
{
ret.ilen++;
}
return ret;
}
Bignum sub(Bignum x,Bignum y)
{
Bignum ret=zero;
for(int i=1;i<=y.ilen;i++)
{
ret.a[i]+=x.a[i]-y.a[i];
if(ret.a[i]<0)
{
ret.a[i]+=10;
ret.a[i+1]--;
}
}
for(int i=y.ilen+1;i<=x.ilen;i++)
{
ret.a[i]+=x.a[i];
}
ret.ilen=x.ilen;
while(!ret.a[ret.ilen]&&ret.ilen>1)
{
ret.ilen--;
}
return ret;
}
int main()
{
scanf("%d",&n);
f[1].a[1]=1;
f[1].ilen=1;
f[2].a[1]=5;
f[2].ilen=1;
f[3].a[1]=6;
f[3].a[2]=1;
f[3].ilen=2;
for(int i=4;i<=n;i++)
{
f[i]=mul(f[i-1]);
f[i]=add(f[i]);
f[i]=sub(f[i],f[i-2]);
}
for(int i=f[n].ilen;i>=1;i--)
{
printf("%d",f[n].a[i]);
}
printf("\n");
return 0;
}

  

bzoj 1002的更多相关文章

  1. bzoj 1002 [FJOI2007]轮状病毒 高精度&&找规律&&基尔霍夫矩阵

    1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2234  Solved: 1227[Submit][Statu ...

  2. BZOJ 1002 轮状病毒

    Description 给定n(N<=100),编程计算有多少个不同的n轮状病毒. Input 第一行有1个正整数n. Output 将编程计算出的不同的n轮状病毒数输出 Sample Inpu ...

  3. 生成树的计数(基尔霍夫矩阵):BZOJ 1002 [FJOI2007]轮状病毒

    1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 3928  Solved: 2154[Submit][Statu ...

  4. BZOJ 1002 [FJOI2007]轮状病毒

    1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 3106  Solved: 1724[Submit][Statu ...

  5. BZOJ 1002: [FJOI2007]轮状病毒【生成树的计数与基尔霍夫矩阵简单讲解+高精度】

    1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 5577  Solved: 3031[Submit][Statu ...

  6. BZOJ 1002 - 轮状病毒 - [基尔霍夫矩阵(待补)+高精度]

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1002 Description 轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生 ...

  7. bzoj 1002 [FJOI2007]轮状病毒——打表找规律

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1002 看 Zinn 的博客:https://www.cnblogs.com/Zinn/p/9 ...

  8. BZOJ 1002 轮状病毒 矩阵树定理

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1002 题目大意: 给定n(N<=100),编程计算有多少个不同的n轮状病毒 思路 ...

  9. AC日记——[FJOI2007]轮状病毒 bzoj 1002

    1002 思路: 打表找规律: dp[i]=dp[i-1]*3-dp[i-2]+2; 套个高精就a了: 代码: #include <cstdio> #include <cstring ...

  10. BZOJ 1002 [ FJOI 2007 ]

    -------------------------萌萌哒分割线------------------------- 题目很容易看懂,数据范围也不大.当然可以卡过暴力的人了. 在n=1时很明显是一种,如下 ...

随机推荐

  1. Struts2基础2

    一.struts中的API 1)完全解耦合的方式 1.1首先创建一个示例工程,在WEB-INF下创建lib文件夹,把struts2核心jar包导入.在工程下创建resource文件夹,并将其设为资源文 ...

  2. Menu显示三个点,不显示内容

    先说下menu的使用 首先自定义一个menu选项 <menu xmlns:android="http://schemas.android.com/apk/res/android&quo ...

  3. kotlin中“==”和“===”的区别

    code 1 fun main(args: Array<String>) { val a : Int = 1000 println(a == a) //true println(a === ...

  4. Linux 脚本/脚本实现思路

  5. wx小程序-音频视频!

    1.音乐的启动跟暂停 dom里面图片切换的另一种方法 通过变量 改变路径 2.监听 在onload里面 3.定义了一个全局变量 然后在但页面中获取 app.js 单页面中 app.js 的三个生命周期

  6. 统计分析与R软件-chapter2-6

    2.6 列表与数据框 2.6.1 列表 1.列表的构造 列表是一种特别的对象集合,它的元素也由序号(下标)区分,但是各元素的类型可以是任意对象,不同元素不必是同一类型,元素本身允许是其他复杂数据类型, ...

  7. js中 && 和 || 的用法

    js中的&& 和 || 一直以为是php那一套,上网查了一些资料,才发现不一样 a() && b() :如果执行a()后返回true,则执行b()并返回b的值:如果执行 ...

  8. k64 datasheet学习笔记11---Port Control and Interrupts (PORT)

    1.前言 Port Control and Interrupt (PORT)  模块提供了port control,digital filtering,和外部中断功能 每个pin的大部分功能可被独立配 ...

  9. DeprecationWarning: Calling an asynchronous function without callback is deprecated. - how to find where the “function:” is?

    I recently updated my node to 7.2.1 and noticed that there is a warning coming: (node:4346) Deprecat ...

  10. windowns下excel2013快速生成月报表

    作者:邓聪聪 windowns下excel快速生成月报表,省去了手工复制繁琐的过程 Sub AutoCopySheets() Dim i, j As Integer i = 1 j = 11 For ...