BZOJ 1002 - 轮状病毒 - [基尔霍夫矩阵(待补)+高精度]
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1002
Description
轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生的。一个N轮状基由圆环上N个不同的基原子
和圆心处一个核原子构成的,2个原子之间的边表示这2个原子之间的信息通道。如下图所示
.png)
N轮状病毒的产生规律是在一个N轮状基中删去若干条边,使得各原子之间有唯一的信息通道,例如共有16个不
同的3轮状病毒,如下图所示
.png)
现给定n(N<=100),编程计算有多少个不同的n轮状病毒
Input
第一行有1个正整数n
Output
计算出的不同的n轮状病毒数输出
Sample Input
3
Sample Output
16
题意:
递推公式 $f[i] = f[i-1] \times 3 - f[i-2] + 2$。
题解:
#include<bits/stdc++.h>
using namespace std;
const int maxn=; struct BigInt
{
static const int maxdigit=;
int len,d[maxn]; void clean(){while(len> && !d[len-]) len--;}
string str()const
{
string s;
for(int i=;i<len;i++) s+=d[len--i]+'';
return s;
} BigInt(){memset(d,,sizeof(d));len=;}
BigInt(int num){*this=num;}
BigInt(char* num){*this=num;} bool operator<(const BigInt& oth)const
{
if(len!=oth.len) return len<oth.len;
for(int i=len-;i>=;i--) if(d[i]!=oth.d[i]) return d[i]<oth.d[i];
return false;
}
bool operator>(const BigInt& oth)const{return oth<*this;}
bool operator<=(const BigInt& oth)const{return !(oth<*this);}
bool operator>=(const BigInt& oth)const{return !(*this<oth);}
bool operator!=(const BigInt& oth)const{return oth<*this || *this<oth;}
bool operator==(const BigInt& oth)const{return !(oth<*this) && !(*this<oth);} BigInt operator=(const char* num)
{
memset(d,,sizeof(d));
len=strlen(num);
for(int i=;i<len;i++) d[i]=num[len--i]-'';
clean();
return *this;
}
BigInt operator=(int num)
{
char s[];
sprintf(s,"%d",num);
return *this=s;
}
BigInt operator+(const BigInt& oth)const
{
BigInt c;
c.len=max(len,oth.len);
for(int i=;i<=c.len;i++) c.d[i]=;
for(int i=;i<c.len;i++)
{
c.d[i]+=(i<len?d[i]:)+(i<oth.len?oth.d[i]:);
c.d[i+]+=c.d[i]/;
c.d[i]%=;
}
c.len+=(c.d[c.len]>);
c.clean();
return c;
}
BigInt operator-(const BigInt& oth)const
{
BigInt c=*this;
if(c<oth) printf("Produce negative number!\n");
int i;
for(i=;i<oth.len;i++)
{
c.d[i]-=oth.d[i];
if(c.d[i]<) c.d[i]+=, c.d[i+]--;
}
while(c.d[i]<) c.d[i++]+=, c.d[i]--;
c.clean();
return c;
}
BigInt operator*(const BigInt& oth)const
{
BigInt c;
for(int i=;i<len;i++) for(int j=;j<oth.len;j++) c.d[i+j]+=d[i]*oth.d[j];
for(int i=;i<len+oth.len || !c.d[i];c.len=++i) c.d[i+]+=c.d[i]/, c.d[i]%=;
c.clean();
return c;
}
BigInt operator/(const BigInt& oth)const
{
BigInt c=*this, r=;
for(int i=;i<len;i++)
{
r=r*+c.d[len--i];
int j;
for(j=;j<;j++) if(r<oth*(j+)) break;
c.d[len--i]=j;
r=r-oth*j;
}
c.clean();
return c;
}
BigInt operator%(const BigInt& oth)
{
BigInt r=;
for(int i=;i<len;i++)
{
r=r*+d[len--i];
int j;
for(j=;j<;j++) if(r<oth*(j+)) break;
r=r-oth*j;
}
return r;
}
BigInt operator+=(const BigInt& oth)
{
*this=*this+oth;
return *this;
}
BigInt operator*=(const BigInt& oth)
{
*this=*this*oth;
return *this;
}
BigInt operator-=(const BigInt& oth)
{
*this=*this-oth;
return *this;
}
BigInt operator/=(const BigInt& oth)
{
*this=*this/oth;
return *this;
}
};
istream& operator>>(istream& in, BigInt& x)
{
string s;
in>>s;
x=s.c_str();
return in;
}
ostream& operator<<(ostream& out,const BigInt& x)
{
out<<x.str();
return out;
} int n;
BigInt f[maxn];
int main()
{
cin>>n;
f[]=;
f[]=;
for(int i=;i<=n;i++) f[i]=(f[i-]*-f[i-]+);
cout<<f[n]<<endl;
}
BZOJ 1002 - 轮状病毒 - [基尔霍夫矩阵(待补)+高精度]的更多相关文章
- BZOJ 1002: [FJOI2007]轮状病毒【生成树的计数与基尔霍夫矩阵简单讲解+高精度】
1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 5577 Solved: 3031[Submit][Statu ...
- bzoj1002: [FJOI2007]轮状病毒(基尔霍夫矩阵)
1002: [FJOI2007]轮状病毒 题目:传送门 题解: 决定开始板刷的第一题... 看到这题的时候想:这不就是求有多少种最小生成树的方式吗? 不会啊!!!%题解... 什么鬼?基尔霍夫矩阵?? ...
- [bzoj1002] [FJOI2007]轮状病毒轮状病毒(基尔霍夫矩阵)
Description 轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生的.一个N轮状基由圆环上N个不同的基原子 和圆心处一个核原子构成的,2个原子之间的边表示这2个原子之间的信息通道.如下 ...
- 【BZOJ】1002:轮状病毒(基尔霍夫矩阵【附公式推导】或打表)
Description 轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生的.一个N轮状基由圆环上N个不同的基原子和圆心处一个核原子构成的,2个原子之间的边表示这2个原子之间的信息通道.如下图 ...
- bzoj 1002 [FJOI2007]轮状病毒 高精度&&找规律&&基尔霍夫矩阵
1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2234 Solved: 1227[Submit][Statu ...
- bzoj 1002 找规律(基尔霍夫矩阵)
网上说的是什么基尔霍夫矩阵,没学过这个,打个表找下规律,发现 w[i]=3*w[i-1]-w[i-2]+2; 然后写个高精直接递推就行了 //By BLADEVIL var n :longint; a ...
- BZOJ1002 FJOI2007 轮状病毒 【基尔霍夫矩阵+高精度】
BZOJ1002 FJOI2007 轮状病毒 Description 轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生的.一个N轮状基由圆环上N个不同的基原子和圆心处一个核原子构成的,2个原 ...
- BZOJ 4031 HEOI2015 小Z的房间 基尔霍夫矩阵+行列式+高斯消元 (附带行列式小结)
原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4031 Description 你突然有了一个大房子,房子里面有一些房间.事实上,你的房子可 ...
- bzoj1002 轮状病毒 暴力打标找规律/基尔霍夫矩阵+高斯消元
基本思路: 1.先观察规律,写写画画未果 2.写程序暴力打表找规律,找出规律 1-15的答案:1 5 16 45 121 320 841 2205 5776 151 ...
随机推荐
- Nginx 设置域名转向配置
#运行用户 #user www-data; #启动进程,通常设置成和cpu的数量相等 worker_processes 2; #全局错误日志及PID文件 error_log logs/error.lo ...
- Keepalived源码安装
1.编译.安装 # tar -xvf keepalived-1.3.9.tar.gz # cd keepalived-1.3.9/ # ./configure -prefix=/usr/local/k ...
- Android BLE蓝牙开发-读写数据 获取UUID
https://www.jianshu.com/p/3711cfbf7128 一个ble蓝牙设备有多个包括多个Profile 一个Profile中有多个服务Service(通过服务的uuid找到对应的 ...
- Python gensim库word2vec 基本用法
ip install gensim安装好库后,即可导入使用: 1.训练模型定义 from gensim.models import Word2Vec model = Word2Vec(senten ...
- Activity标题(title)的显示和隐藏
开发Android应用程序,我们总会遇到Activity的title把显示的内容遮挡了一部分.如果能把它去掉,我们的应用界面就会变得更加简洁,那该多好.下面有两种方法可以去掉: (方法一):通过一句J ...
- springboot集成redis缓存
1.pom.xml增加redis缓存起步依赖(spring-boot-starter-parent包含许多starter版本) <dependency> <groupId>or ...
- Unity实现混合模式的ADD模式
一般来说,2D的特效都会用到ADD模式来播放,但是Unity居然没有内置任何的混合模式,网上资料太少,没有写好的Shader,这里提供下我自己编写Shader: Shader "Unlit/ ...
- flink source code
https://github.com/apache/flink/tree/master/docs https://github.com/flink-china/1.6.0 https://github ...
- WebMisSharp,WebMisCentral,企业框架正则表达式规则共享专版
ElegantWM.WebUI/Application/common/src/Tools.js 欢迎大家贡献更多的正则验证规则,目前支持如下: /*************************** ...
- 树莓派设置静态IP地址
树莓派设置静态IP地址http://www.jianshu.com/p/b0e6d066d6b6 ——————————————————————————————————————————————————— ...