[Luogu P2144] [BZOJ 1002] [FJOI2007]轮状病毒

洛谷传送门
BZOJ传送门

题目描述

轮状病毒有很多变种。许多轮状病毒都是由一个轮状基产生。一个 n n 轮状基由圆环上n个不同的基原子和圆心的一个核原子构成。 2 2 个原子之间的边表示这2个原子之间的信息通道,如图 1 1

n轮状病毒的产生规律是在 n n 轮状基中删除若干边,使各原子之间有唯一一条信息通道。例如,共有16个不同的 3 3 轮状病毒,入图2所示。

给定n(N<=100),编程计算有多少个不同的 n n 轮状病毒。

img

输入输出格式

输入格式:

第一行有1个正整数 n n

输出格式:

将编程计算出的不同的n轮状病毒数输出

输入输出样例

输入样例#1:
3
输出样例#1:
16

解题分析

据说正解是矩阵树加容斥再加高精度?貌似还卡常?蒟蒻不会…只好递推。

我们先考虑将四周的点放在一个圆上, 并且圆的正上方的点和其左端的点不相连。设 F[i] F [ i ] 为四周有 i i 个点时的方案数。

可以很容易发现F[i]=j=1i1F[j]×(ij),因为加入一个大小为 k k 的联通块的时候,中心可以有k种方式向其连边。

但这样搞会少算一些情况, 即最上方的点与其左方的点相连的情况。设第一个联通块大小为 x x , 那么通过旋转总共有x中情况。 所以最终的式子是:

F[i]=j=1n1F[j]×(ij)+j=1nj×j F [ i ] = ∑ j = 1 n − 1 F [ j ] × ( i − j ) + ∑ j = 1 n j × j

完美套上高精板子…

代码如下:

#include <string>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#define R register
namespace BigInteger
{
#define maxn 10005
using std::sprintf;
using std::string;
using std::max;
using std::istream;
using std::ostream;

struct Big_integer{  
    int d[maxn], len;  

    void clean() { while(len > 1 && !d[len-1]) len--; }  

    Big_integer()          { memset(d, 0, sizeof(d)); len = 1; }  
    Big_integer(int num)   { *this = num; }   
    Big_integer(char* num) { *this = num; }  
    Big_integer operator = (const char* num){  
        memset(d, 0, sizeof(d)); len = strlen(num);  
        for(int i = 0; i < len; i++) d[i] = num[len-1-i] - '0';  
        clean();  
        return *this;  
    }  

    Big_integer operator = (int num){  
        char s[10005]; sprintf(s, "%d", num);  
        *this = s;  
        return *this;  
    }  

    Big_integer operator + (const Big_integer& b){  
        Big_integer c = *this; int i;  
        for (i = 0; i < b.len; i++){  
            c.d[i] += b.d[i];  
            if (c.d[i] > 9) c.d[i]%=10, c.d[i+1]++;  
        }  
        while (c.d[i] > 9) c.d[i++]%=10, c.d[i]++;  
        c.len = max(len, b.len);  
        if (c.d[i] && c.len <= i) c.len = i+1;  
        return c;  
    }  

    Big_integer operator - (const Big_integer& b){  
        Big_integer c = *this; int i;  
        for (i = 0; i < b.len; i++){  
            c.d[i] -= b.d[i];  
            if (c.d[i] < 0) c.d[i]+=10, c.d[i+1]--;  
        }  
        while (c.d[i] < 0) c.d[i++]+=10, c.d[i]--;  
        c.clean();  
        return c;  
    }  

    Big_integer operator * (const Big_integer& b)const{  
        int i, j; Big_integer c; c.len = len + b.len;   
        for(j = 0; j < b.len; j++) for(i = 0; i < len; i++)   
            c.d[i+j] += d[i] * b.d[j];  
        for(i = 0; i < c.len-1; i++)  
            c.d[i+1] += c.d[i]/10, c.d[i] %= 10;  
        c.clean();  
        return c;  
    }  

    Big_integer operator / (const Big_integer& b){  
        int i, j;  
        Big_integer c = *this, a = 0;  
        for (i = len - 1; i >= 0; i--)  
        {  
            a = a*10 + d[i];  
            for (j = 0; j < 10; j++) if (a < b*(j+1)) break;  
            c.d[i] = j;  
            a = a - b*j;  
        }  
        c.clean();  
        return c;  
    }  

    Big_integer operator % (const Big_integer& b){  
        int i, j;  
        Big_integer a = 0;  
        for (i = len - 1; i >= 0; i--)  
        {  
            a = a*10 + d[i];  
            for (j = 0; j < 10; j++) if (a < b*(j+1)) break;  
            a = a - b*j;  
        }  
        return a;  
    }  

    Big_integer operator += (const Big_integer& b){  
        *this = *this + b;  
        return *this;  
    }  

    bool operator <(const Big_integer& b) const{  
        if(len != b.len) return len < b.len;  
        for(int i = len-1; i >= 0; i--)  
            if(d[i] != b.d[i]) return d[i] < b.d[i];  
        return false;  
    }  
    bool operator >(const Big_integer& b) const{return b < *this;}  
    bool operator<=(const Big_integer& b) const{return !(b < *this);}  
    bool operator>=(const Big_integer& b) const{return !(*this < b);}  
    bool operator!=(const Big_integer& b) const{return b < *this || *this < b;}  
    bool operator==(const Big_integer& b) const{return !(b < *this) && !(b > *this);}  

    string str() const{  
        char s[maxn]={};  
        for(int i = 0; i < len; i++) s[len-1-i] = d[i]+'0';  
        return s;  
    }  
};  

istream& operator >> (istream& in, Big_integer& x)  
{  
    string s;  
    in >> s;  
    x = s.c_str();  
    return in;  
}  

ostream& operator << (ostream& out, const Big_integer& x)  
{  
    out << x.str();  
    return out;  
}  
}
using namespace BigInteger;
Big_integer F[105], mul;
int main(void)
{
    int n, bd;
    scanf("%d", &n);
    F[0] = 1;
    for (R int i = 0; i <= n; ++i)
    {
        bd = n - i;
        for (R int j = 1; j <= bd; ++j)
        {
            if(i == 0) mul = j, F[i + j] += F[i] * mul * mul;
            else F[i + j] += F[i] * j;
        }
    }
    std::cout << F[n];
}

然后我们发现 n100 n ≤ 100 ,所以打个表就好了…

#include <iostream>
#include <string>
using namespace std;
string F[] = {"1", "5", "16", "45", "121", "320", "841", "2205", "5776", "15125", "39601", "103680", "271441", "710645", "1860496", "4870845", "12752041", "33385280", "87403801", "228826125", "599074576", "1568397605", "4106118241", "10749957120", "28143753121", "73681302245", "192900153616", "505019158605", "1322157322201", "3461452808000", "9062201101801", "23725150497405", "62113250390416", "162614600673845", "425730551631121", "1114577054219520", "2918000611027441", "7639424778862805", "20000273725560976", "52361396397820125", "137083915467899401", "358890350005878080", "939587134549734841", "2459871053643326445", "6440026026380244496", "16860207025497407045", "44140595050111976641", "115561578124838522880", "302544139324403592001", "792070839848372253125", "2073668380220713167376", "5428934300813767249005", "14213134522220588579641", "37210469265847998489920", "97418273275323406890121", "255044350560122222180445", "667714778405043259651216", "1748099984655007556773205", "4576585175559979410668401", "11981655542024930675232000", "31368381450514812615027601", "82123488809519507169850805", "215002084978043708894524816", "562882766124611619513723645", "1473646213395791149646646121", "3858055874062761829426214720", "10100521408792494338631998041", "26443508352314721186469779405", "69230003648151669220777340176", "181246502592140286475862241125", "474509504128269190206809383201", "1242282009792667284144565908480", "3252336525249732662226888342241", "8514727565956530702536099118245", "22291846172619859445381409012496", "58360810951903047633608127919245", "152790586683089283455442974745241", "400010949097364802732720796316480", "1047242260609005124742719414204201", "2741715832729650571495437446296125", "7177905237579946589743592924684176", "18791999880010189197735341327756405", "49198094402450621003462431058585041", "128802283327341673812651951847998720", "337208755579574400434493424485411121", "882823983411381527490828321608234645", "2311263194654570182037991540339292816", "6050965600552329018623146299409643805", "15841633607002416873831447357889638601", "41473935220454921602871195774259272000", "108580172054362347934782139964888177401", "284266580942632122201475224120405260205", "744219570773534018669643532396327603216", "1948392131377969933807455373068577549445", "5100956823360375782752722586809405045121", "13354478338703157414450712387359637585920", "34962478192749096460599414575269507712641", "91532956239544131967347531338448885552005", "239636390525883299441443179440077148943376", "627376215338105766356982006981782561278125"};
int main(void)
{
    int n;
    cin >> n;
    cout << F[n - 1];
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值