@[暴搜, 找規律, 高精度]

Description

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



\(n\)轮状病毒的产生规律是在一个\(n\)轮状基中删去若干条边,使得各原子之间有唯一的信息通道,例如共有\(16\)个不

同的3轮状病毒,如下图所示



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

Input

1个正整数n

Output

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

Sample Input

3

Sample Output

16

Solution

先暴搜找規律(結果爆搜就打了好久\(QAQ\))

#include<cstdio>
#include<cctype>
#include<cstring>
using namespace std;
inline int read()
{
int x = 0, flag = 1;;
char c;
while(! isdigit(c = getchar()))
if(c == '-')
flag *= - 1;
while(isdigit(c))
x = x * 10 + c - '0', c = getchar();
return x * flag;
}
void println(int x)
{
if(x < 0)
putchar('-'), x *= - 1;
if(x == 0)
putchar('0');
int ans[10], top = 0;
while(x)
ans[top ++] = x % 10, x /= 10;
for(; top; top --)
putchar(ans[top - 1] + '0');
putchar('\n');
}
int n;
struct Edge
{
int u, v;
}G[100];
int ans;
int fa[16];
int find(int x)
{
if(fa[x] == x)
return x;
return fa[x] = find(fa[x]);
}
void search(int x, int top, int cnt)
{
if(cnt == n)
{
ans ++;
return;
}
if(x == top)
return;
search(x + 1, top, cnt);
int _fa[16]; //并查集很執行難撤回操作, 因此只能用這種比較笨的辦法來搞
for(int i = 0; i <= n; i ++)
_fa[i] = fa[i];
int fu = find(G[x].u), fv = find(G[x].v);
if(fu == fv)
return;
fa[fu] = fv;
search(x + 1, top, cnt + 1);
for(int i = 0; i <= n; i ++)
fa[i] = _fa[i];
}
int main()
{
for(int i = 2; i < 16; i ++)
{
n = i;
for(int j = 0; j < n; j ++)
G[j].u = 0, G[j].v = j + 1;
for(int j = n; j < (n << 1); j ++)
G[j].u = j - n + 1, G[j].v = j - n + 2;
G[(n << 1) - 1].v = 1;
for(int i = 0; i <= n; i ++)
fa[i] = i;
ans = 0;
search(0, n << 1, 0);
println(ans);
}
}

得到輸出數據

5
16
45
121
320
841
2205
5776
15125
39601
103680
271441
710645
1860496 --------------------------------
Process exited after 70.46 seconds with return value 0
请按任意键继续. . .

通過待定係數法可得, 對於\(n\)輪狀病毒有種類數

\(f(n) = f(n - 1) * 3 - f(n - 2) + 2\)

注意到當 \(n = 100\) 時\(f(n)\) 會變得很大, 所以要寫高精度...

#include<cstdio>
#include<cctype>
#include<cstring>
using namespace std;
inline int read()
{
int x = 0, flag = 1;;
char c;
while(! isgraph(c = getchar()))
if(c == '-')
flag *= - 1;
while(isgraph(c))
x = x * 10 + c - '0', c = getchar();
return x * flag;
}
void println(int x)
{
if(x < 0)
putchar('-'), x *= - 1;
if(x == 0)
putchar('0');
int ans[10], top = 0;
while(x)
ans[top ++] = x % 10, x /= 10;
for(; top; top --)
putchar(ans[top - 1] + '0');
putchar('\n');
}
const int N = 1 << 7;
struct Giant
{
int dig[1 << 10];
int top;
}f[N];
Giant operator *(Giant x, int y)
{
for(int i = 0; i < x.top; i ++)
x.dig[i] *= y;
for(int i = 0; i < x.top; i ++)
x.dig[i + 1] += x.dig[i] / 10, x.dig[i] %= 10;
if(x.dig[x.top])
x.top ++;
return x;
}
Giant operator -(Giant x, Giant y)
{
for(int i = 0; i < x.top; i ++)
{
x.dig[i] -= y.dig[i];
if(x.dig[i] < 0)
x.dig[i] += 10, x.dig[i + 1] --;
}
if(! x.dig[x.top - 1])
x.top --;
return x;
}
Giant operator +(Giant x, int y)
{
x.dig[0] += y;
for(int i = 0; i < x.top; i ++)
x.dig[i + 1] += x.dig[i] / 10, x.dig[i] = x.dig[i] % 10;
if(x.dig[x.top])
x.top ++;
return x;
}
void println(Giant &x)
{
for(int i = x.top; i; i --)
putchar(x.dig[i - 1] + '0');
putchar('\n');
}
int main()
{
int n = read();
memset(f, 0, sizeof(f));
f[2].dig[0] = 5, f[2].top = 1;
f[3].dig[0] = 6, f[3].dig[1] = 1, f[3].top = 2;
for(int i = 4; i <= n; i ++)
f[i] = f[i - 1] * 3 - f[i - 2] + 2;
println(f[n]);
}

BZOJ1002輪狀病毒 暴搜 + 找規律 + 高精度的更多相关文章

  1. 51nod1093(推公式&找規律)

    題目鏈接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1093 題意:中文題誒- 思路:xjb 一開始死活想不出怎麼將一 ...

  2. HDU - 6185 Covering(暴搜+递推+矩阵快速幂)

    Covering Bob's school has a big playground, boys and girls always play games here after school. To p ...

  3. c++20701除法(刘汝佳1、2册第七章,暴搜解决)

    20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述     输入正整数n,按从小到大的顺序输出所有 ...

  4. Codeforces Round #238 (Div. 2) D. Toy Sum 暴搜

    题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chr ...

  5. 子矩阵(暴搜(全排列)+DP)

    子矩阵(暴搜(全排列)+DP) 一.题目 子矩阵 时间限制: 1 Sec  内存限制: 128 MB 提交: 1  解决: 1 [提交][状态][讨论版] 题目描述 给出如下定义: 1. 子矩阵:从一 ...

  6. HDU5952 Counting Cliques 暴搜优化

    一.前言 这题看上去相当唬人(NPC问题),但是 因为限制了一些条件,所以实际上并没有太唬人. 二.题目 给你一个图,要求你找出数量为S的团的数量. 三.题解 暴搜,再加上一些玄学优化. 优化1:使用 ...

  7. hdu 5952 Counting Cliques 求图中指定大小的团的个数 暴搜

    题目链接 题意 给定一个\(n个点,m条边\)的无向图,找出其中大小为\(s\)的完全图个数\((n\leq 100,m\leq 1000,s\leq 10)\). 思路 暴搜. 搜索的时候判断要加进 ...

  8. bzoj 1053 [ HAOI 2007 ] 反素数ant ——暴搜

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1053 试图打表找规律,但无果... 看TJ了,暴搜: 注意参数 w 是 long long. ...

  9. 紫书 习题7-14 UVa 307(暴搜+剪枝)

    这道题一开始我想的是在排序之后只在头和尾往中间靠近来找木块, 然后就WA, 事实证明这种方法是错误的. 然后参考了别人的博客.发现别人是直接暴搜, 但是加了很多剪枝, 所以不会超时. 我也想过这个做法 ...

随机推荐

  1. PHPMailer发送邮件(一)

    Github 地址:(已更新,适用于旧版) PHPMailer : https://github.com/PHPMailer/PHPMailer 一.基本要求 Web访问正常(apache可以正常访问 ...

  2. NYOJ 257 郁闷的C小加(一) (字符串处理)

    题目链接 描述 我们熟悉的表达式如a+b.a+b(c+d)等都属于中缀表达式.中缀表达式就是(对于双目运算符来说)操作符在两个操作数中间:num1 operand num2.同理,后缀表达式就是操作符 ...

  3. HDU 2082 找单词 (普通母函数)

    题目链接 Problem Description 假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于 ...

  4. HDU 1394 Minimum Inversion Number (树状数组)

    题目链接 Problem Description The inversion number of a given number sequence a1, a2, ..., an is the numb ...

  5. Hibernate总结之Hello,World

    1. 引入相关maven依赖: <dependency> <groupId>org.hibernate</groupId> <artifactId>hi ...

  6. BBScan — 一个信息泄漏批量扫描脚本

    github:https://github.com/lijiejie/BBScan 有些朋友手上有几十万甚至上百万个域名,比如,乌云所有厂商的子域名. 如果把这30万个域名全部扔给wvs,APPsca ...

  7. openjudge-NOI 2.6-1996 登山

    题目链接:http://noi.openjudge.cn/ch0206/1996/ 题解: 正反求两次LIS即可 #include<cstdio> #include<cstring& ...

  8. Oracle中的dual

    简介,摘自百度百科: Oracle提供的最小的表,不论进行何种操作(不要删除记录),它都只有一条记录——'X'. 例如:执行select * from dual,里面只有一条记录:执行insert i ...

  9. centos上git搭建

    1 git的安装需要一些包: yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-Ex ...

  10. salt-api起不来:ImportError('No module named wsgiserver2',)

    问题:启动salt-api时没有报错但是没有端口,查看/var/log/salt/api发现如下报错: 解决方法: 下载wsgiserver2文件,放到/usr/lib64/python2.7/sit ...