期中考试成功探底。。。但是某些化学问题还是很有信息学价值的。。。

n 烷同分异构体计数。

这个题 fanhq666 出过,就是一个 dp。

设 f[i] 表示含有 i 个节点的无标号不同构的度数限制为 4 的有根树的个数。那么转移时枚举最多 3 个子树的大小,如果大小相同时用组合数,否则乘法原理就好了。

最后统计答案时找到中心为根,然后最多 4 个子树,每个大小不超过 [n / 2] - 1(除法取上整),同样的累计方法(组合数/乘法原理)统计一下就好了;双重心时需要把两个重心同时提上去统计一遍和刚才的答案累加。

没事闲的写了个比较全的高精度,先贴高精度模板。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std; int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} struct LL {
int len, A[510]; LL() { len = -1; }
LL(int x) {
A[1] = x; len = 1;
if(x) while(A[len] > 9) A[len+1] = A[len] / 10, A[len] %= 10, len++;
else len = -1;
} LL operator = (const int& t) {
A[1] = t; len = 1;
if(t) while(A[len] > 9) A[len+1] = A[len] / 10, A[len] %= 10, len++;
else len = -1;
return *this;
} LL operator + (const LL& t) const {
LL ans; ans.len = max(len, t.len);
for(int i = 1; i <= ans.len; i++) ans.A[i] = (i <= len ? A[i] : 0) + (i <= t.len ? t.A[i] : 0);
for(int i = 1; i < ans.len; i++) if(ans.A[i] > 9) ans.A[i+1] += ans.A[i] / 10, ans.A[i] %= 10;
while(ans.A[ans.len] > 9) ans.A[ans.len+1] = ans.A[ans.len] / 10, ans.A[ans.len] %= 10, ans.len++;
return ans;
}
LL operator += (const LL& t) {
*this = *this + t;
return *this;
}
LL operator + (const int& t) const {
LL ans; ans.len = max(len, 1);
for(int i = 1; i <= ans.len; i++) ans.A[i] = A[i]; ans.A[1] += t;
for(int i = 1; i < ans.len; i++) if(ans.A[i] > 9) ans.A[i+1] += ans.A[i] / 10, ans.A[i] %= 10;
while(ans.A[ans.len] > 9) ans.A[ans.len+1] = ans.A[ans.len] / 10, ans.A[ans.len] %= 10, ans.len++;
return ans;
}
LL operator += (const int& t) {
*this = *this + t;
return *this;
}
LL operator ++ () { // ++this;
*this = *this + 1;
return *this;
}
LL operator ++ (int x) { // this++;
*this = *this + 1;
return *this - 1;
} LL operator - (const LL& t) const {
LL ans; ans.len = max(len, t.len);
for(int i = 1; i <= ans.len; i++) ans.A[i] = A[i] - t.A[i];
for(int i = 1; i < ans.len; i++) if(ans.A[i] < 0) {
int tmp = (-ans.A[i] + 9) / 10;
ans.A[i+1] -= tmp; ans.A[i] += tmp * 10;
}
while(!ans.A[ans.len]) ans.len--;
return ans;
}
LL operator -= (const LL& t) {
*this = *this - t;
return *this;
}
LL operator - (const int& t) const {
LL ans; ans.len = len;
for(int i = 1; i <= ans.len; i++) ans.A[i] = A[i]; ans.A[1] -= t;
for(int i = 1; i < ans.len; i++) if(ans.A[i] < 0) {
int tmp = (-ans.A[i] + 9) / 10;
ans.A[i+1] -= tmp; ans.A[i] += tmp * 10;
}
while(!ans.A[ans.len]) ans.len--;
return ans;
}
LL operator -= (const int& t) {
*this = *this - t;
return *this;
}
LL operator -- () { // --this;
*this = *this - 1;
return *this;
}
LL operator -- (int x) { // this--;
*this = *this - 1;
return *this + 1;
} LL operator * (const LL& t) const {
LL ans; ans.len = len + t.len - 1;
if(len < 0 || t.len < 0) return ans.len = -1, ans;
for(int i = 1; i <= ans.len; i++) ans.A[i] = 0;
for(int i = 1; i <= len; i++)
for(int j = 1; j <= t.len; j++) ans.A[i+j-1] += A[i] * t.A[j];
for(int i = 1; i < ans.len; i++) if(ans.A[i] > 9) ans.A[i+1] += ans.A[i] / 10, ans.A[i] %= 10;
while(ans.A[ans.len] > 9) ans.A[ans.len+1] = ans.A[ans.len] / 10, ans.A[ans.len] %= 10, ans.len++;
return ans;
}
LL operator *= (const LL& t) {
*this = *this * t;
return *this;
}
LL operator * (const int& t) const {
LL ans = t;
return ans * (*this);
}
LL operator *= (const int& t) {
*this = *this * t;
return *this;
} bool operator < (const LL& t) const {
if(len != t.len) return len < t.len;
for(int i = len; i > 0; i--) if(A[i] != t.A[i]) return A[i] < t.A[i];
return 0;
}
bool operator > (const LL& t) const {
if(len != t.len) return len > t.len;
for(int i = len; i > 0; i--) if(A[i] != t.A[i]) return A[i] > t.A[i];
return 0;
}
bool operator == (const LL& t) const {
if(len != t.len) return 0;
for(int i = len; i > 0; i--) if(A[i] != t.A[i]) return 0;
return 1;
}
bool operator != (const LL& t) const {
return !((*this) == t);
}
bool operator <= (const LL& t) const {
return *this < t || *this == t;
}
bool operator >= (const LL& t) const {
return *this > t || *this == t;
} LL operator / (const LL& t) const {
LL ans, f = 0; ans.len = -1;
for(int i = 1; i <= len; i++) ans.A[i] = 0;
for(int i = len; i > 0; i--) {
f = f * 10 + A[i];
while(f >= t) {
f -= t; ans.A[i]++;
ans.len = max(ans.len, i);
}
}
return ans;
}
LL operator /= (const LL& t) {
*this = *this / t;
return *this;
}
LL operator / (const int& t) const {
LL ans; int f = 0; ans.len = -1;
for(int i = 1; i <= len; i++) ans.A[i] = 0;
for(int i = len; i > 0; i--) {
f = f * 10 + A[i];
while(f >= t) {
f -= t; ans.A[i]++;
ans.len = max(ans.len, i);
}
}
return ans;
}
LL operator /= (const int& t) {
*this = *this / t;
return *this;
} void print() {
if(len < 0){ putchar('0'); return ; }
for(int i = len; i > 0; i--) putchar(A[i] + '0'); putchar('\n');
return ;
}
} A, B; int main() {
while(1) {
A = read(); B = read();
(A + B).print();
(A - B).print();
(A * B).print();
(A / B).print();
(A++).print();
(++A).print();
(B--).print();
(--B).print();
} return 0;
}
/*
8997622 2333
*/

再贴这道题的程序。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
using namespace std; int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 1010 struct LL {
int len, A[510]; LL() { len = -1; }
LL(int x) {
A[1] = x; len = 1;
if(x) while(A[len] > 9) A[len+1] = A[len] / 10, A[len] %= 10, len++;
else len = -1;
} LL operator = (const int& t) {
A[1] = t; len = 1;
if(t) while(A[len] > 9) A[len+1] = A[len] / 10, A[len] %= 10, len++;
else len = -1;
return *this;
} LL operator + (const LL& t) const {
LL ans; ans.len = max(len, t.len);
for(int i = 1; i <= ans.len; i++) ans.A[i] = (i <= len ? A[i] : 0) + (i <= t.len ? t.A[i] : 0);
for(int i = 1; i < ans.len; i++) if(ans.A[i] > 9) ans.A[i+1] += ans.A[i] / 10, ans.A[i] %= 10;
while(ans.A[ans.len] > 9) ans.A[ans.len+1] = ans.A[ans.len] / 10, ans.A[ans.len] %= 10, ans.len++;
return ans;
}
LL operator += (const LL& t) {
*this = *this + t;
return *this;
}
LL operator + (const int& t) const {
LL ans; ans.len = max(len, 1);
for(int i = 1; i <= ans.len; i++) ans.A[i] = A[i]; ans.A[1] += t;
for(int i = 1; i < ans.len; i++) if(ans.A[i] > 9) ans.A[i+1] += ans.A[i] / 10, ans.A[i] %= 10;
while(ans.A[ans.len] > 9) ans.A[ans.len+1] = ans.A[ans.len] / 10, ans.A[ans.len] %= 10, ans.len++;
return ans;
}
LL operator += (const int& t) {
*this = *this + t;
return *this;
}
LL operator ++ () { // ++this;
*this = *this + 1;
return *this;
}
LL operator ++ (int x) { // this++;
*this = *this + 1;
return *this - 1;
} LL operator - (const LL& t) const {
LL ans; ans.len = max(len, t.len);
for(int i = 1; i <= ans.len; i++) ans.A[i] = A[i] - t.A[i];
for(int i = 1; i < ans.len; i++) if(ans.A[i] < 0) {
int tmp = (-ans.A[i] + 9) / 10;
ans.A[i+1] -= tmp; ans.A[i] += tmp * 10;
}
while(!ans.A[ans.len]) ans.len--;
return ans;
}
LL operator -= (const LL& t) {
*this = *this - t;
return *this;
}
LL operator - (const int& t) const {
LL ans; ans.len = len;
for(int i = 1; i <= ans.len; i++) ans.A[i] = A[i]; ans.A[1] -= t;
for(int i = 1; i < ans.len; i++) if(ans.A[i] < 0) {
int tmp = (-ans.A[i] + 9) / 10;
ans.A[i+1] -= tmp; ans.A[i] += tmp * 10;
}
while(!ans.A[ans.len]) ans.len--;
return ans;
}
LL operator -= (const int& t) {
*this = *this - t;
return *this;
}
LL operator -- () { // --this;
*this = *this - 1;
return *this;
}
LL operator -- (int x) { // this--;
*this = *this - 1;
return *this + 1;
} LL operator * (const LL& t) const {
LL ans; ans.len = len + t.len - 1;
if(len < 0 || t.len < 0) return ans.len = -1, ans;
for(int i = 1; i <= ans.len; i++) ans.A[i] = 0;
for(int i = 1; i <= len; i++)
for(int j = 1; j <= t.len; j++) ans.A[i+j-1] += A[i] * t.A[j];
for(int i = 1; i < ans.len; i++) if(ans.A[i] > 9) ans.A[i+1] += ans.A[i] / 10, ans.A[i] %= 10;
while(ans.A[ans.len] > 9) ans.A[ans.len+1] = ans.A[ans.len] / 10, ans.A[ans.len] %= 10, ans.len++;
return ans;
}
LL operator *= (const LL& t) {
*this = *this * t;
return *this;
}
LL operator * (const int& t) const {
LL ans = t;
return ans * (*this);
}
LL operator *= (const int& t) {
*this = *this * t;
return *this;
} bool operator < (const LL& t) const {
if(len != t.len) return len < t.len;
for(int i = len; i > 0; i--) if(A[i] != t.A[i]) return A[i] < t.A[i];
return 0;
}
bool operator > (const LL& t) const {
if(len != t.len) return len > t.len;
for(int i = len; i > 0; i--) if(A[i] != t.A[i]) return A[i] > t.A[i];
return 0;
}
bool operator == (const LL& t) const {
if(len != t.len) return 0;
for(int i = len; i > 0; i--) if(A[i] != t.A[i]) return 0;
return 1;
}
bool operator != (const LL& t) const {
return !((*this) == t);
}
bool operator <= (const LL& t) const {
return *this < t || *this == t;
}
bool operator >= (const LL& t) const {
return *this > t || *this == t;
} LL operator / (const LL& t) const {
LL ans, f = 0; ans.len = -1;
for(int i = 1; i <= len; i++) ans.A[i] = 0;
for(int i = len; i > 0; i--) {
f = f * 10 + A[i];
while(f >= t) {
f -= t; ans.A[i]++;
ans.len = max(ans.len, i);
}
}
return ans;
}
LL operator /= (const LL& t) {
*this = *this / t;
return *this;
}
LL operator / (const int& t) const {
LL ans; int f = 0; ans.len = -1;
for(int i = 1; i <= len; i++) ans.A[i] = 0;
for(int i = len; i > 0; i--) {
f = f * 10 + A[i];
while(f >= t) {
f -= t; ans.A[i]++;
ans.len = max(ans.len, i);
}
}
return ans;
}
LL operator /= (const int& t) {
*this = *this / t;
return *this;
} void print() {
if(len < 0){ putchar('0'); return ; }
for(int i = len; i > 0; i--) putchar(A[i] + '0');
return ;
}
}; LL f[maxn];
LL C(LL n, int m) {
LL sum = 1;
for(LL i = n; i >= n - m + 1; i--) sum *= i;
for(int i = 1; i <= m; i++) sum /= i;
return sum;
}
LL dp(int n) {
LL& ans = f[n];
if(ans > 0) return ans;
if(!n) return ans = 1;
// printf("dp(%d)\n", n);
for(int s1 = n - 1; s1 >= 0; s1--)
for(int s2 = s1; s2 >= 0; s2--) {
int s3 = n - s1 - s2 - 1;
if(s3 < 0) continue;
if(s2 < s3) break;
// printf("%d %d %d\n", s1, s2, s3);
if(s1 == s3) ans += C(dp(s1) + 2, 3);
else if(s1 == s2)
ans += C(dp(s1) + 1, 2) * dp(s3);
else if(s2 == s3)
ans += C(dp(s2) + 1, 2) * dp(s1);
else ans += dp(s1) * dp(s2) * dp(s3);
// printf("dp(%d): %lld\n", n, ans);
}
// printf("%d: %d\n", n, ans);
return ans;
} string Names[15] = {"¼×", "ÒÒ", "±û", "¶¡", "Îì", "¼º", "¸ý", "ÐÁ", "ÈÉ", "¹ï"};
string getname(int n) {
if(n <= 10) return Names[n-1] + string("Íé");
char Name[maxn]; memset(Name, 0, sizeof(Name));
sprintf(Name, "%dÍé", n);
return string(Name);
} int main() {
while(1) {
int n = read();
LL ans = 0, getrid = 0;
if(n & 1) {
for(int s1 = (n >> 1); s1 >= 0; s1--)
for(int s2 = s1; s2 >= 0; s2--)
for(int s3 = s2; s3 >= 0; s3--) {
int s4 = n - s1 - s2 - s3 - 1;
if(s4 < 0) continue;
if(s3 < s4) break;
// printf("%d %d %d %d\n", s1, s2, s3, s4);
if(s1 == s4) ans += C(dp(s1) + 3, 4);
else if(s1 == s3) ans += C(dp(s1) + 2, 3) * dp(s4);
else if(s2 == s4) ans += C(dp(s2) + 2, 3) * dp(s1);
else {
int S[4] = {s1, s2, s3, s4}, l = 0, r = 0;
LL tmp = 1;
while(r < 4) {
while(r < 3 && S[l] == S[r+1]) r++;
tmp *= C(dp(S[l]) + r - l, r - l + 1);
l = r = r + 1;
}
ans += tmp;
}
}
}
else {
for(int s1 = (n >> 1) - 1; s1 >= 0; s1--)
for(int s2 = s1; s2 >= 0; s2--)
for(int s3 = s2; s3 >= 0; s3--) {
int s4 = n - s1 - s2 - s3 - 1;
if(s4 < 0) continue;
if(s3 < s4) break;
// printf("%d %d %d %d\n", s1, s2, s3, s4);
if(s1 == s4) ans += C(dp(s1) + 3, 4);
else if(s1 == s3) ans += C(dp(s1) + 2, 3) * dp(s4);
else if(s2 == s4) ans += C(dp(s2) + 2, 3) * dp(s1);
else {
int S[4] = {s1, s2, s3, s4}, l = 0, r = 0;
LL tmp = 1;
while(r < 4) {
while(r < 3 && S[l] == S[r+1]) r++;
tmp *= C(dp(S[l]) + r - l, r - l + 1);
l = r = r + 1;
}
ans += tmp;
}
}
ans += C(dp(n >> 1) + 1, 2);
}
cout << getname(n); printf("ÓÐ "); ans.print(); puts(" ÖÖͬ·ÖÒì¹¹Ìå");
} return 0;
}

复(学)习化学时突然的一个 idea的更多相关文章

  1. PHP进行数据库操作时遇到的一个问题

    PHP进行数据库操作时遇到的一个问题 昨天在进行数据库操作时,遇到了一个问题(用的是 wampserver 环境): <?php $link = @mysqli_connect('localho ...

  2. Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们。

    Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们. 这个是我将鸟哥书上的进行了一下整理的,希望不要涉及到版权问题. 1.显示日期的 ...

  3. 当我学完Python时我学了些什么

    本文是本人学完Python后的一遍回顾,加深理解而已,Python大神请过~ 学习Python的这几天来,觉得Python还是比较简单,容易上手的,就基本语法而言,但是有些高级特性掌握起来还是有些难度 ...

  4. ios 仿新浪微博 UINavigationController 向左滑动时显示上一个控制器的View.

    仿新浪微博 UINavigationController 向左滑动时显示上一个控制器的View. 实现原理,UINavigationController 的 self.view显示时把当前显示的vie ...

  5. L2TP连接尝试失败,因为安全层在初始化与远程计算机的协商时遇到了一个处理错误(转)

    L2TP连接尝试失败,因为安全层在初始化与远程计算机的协商时遇到了一个处理错误   错误描述:“ L2TP连接尝试失败,因为安全层在初始化与远程计算机的协商时遇到了一个处理错误” 只有这个没有错误码. ...

  6. 启动多个eclipse 时,因为一个另一个启动报错,

    启动多个eclipse 时,因为一个另一个启动报错, 原因: 可能是 有一个 eclipse  中 的 tomcat  配置出错:preference中  tomcat 配置  context dec ...

  7. json 数据类型,后台在组数据时,错一个标点符号,前端都解析不出来。

    json 数据类型,后台在组数据时,错一个标点符号,前端都解析不出来.

  8. 在Hive中执行DDL之类的SQL语句时遇到的一个问题

    在Hive中执行DDL之类的SQL语句时遇到的一个问题 作者:天齐 遇到的问题如下: hive> create table ehr_base(id string); FAILED: Execut ...

  9. 安装dede UTF_8时报出了一个致命错误和警告,最后不能显示网站后台和首页了

    安装dede UTF_8时报出了一个致命错误和警告,最后不能显示网站后台和首页了.报错如下: 登陆首页显示:Fatal error: Call to undefined function ParCv( ...

随机推荐

  1. Problem E: 穷游中国在统题 优先队列 + 模拟

    http://www.gdutcode.sinaapp.com/problem.php?cid=1049&pid=4 Problem E: 穷游中国在统题 Description Travel ...

  2. python实战之爬取喜玛拉雅专辑信息

    import urllib.request import json from lxml import etree url='http://www.ximalaya.com/dq/8.ajax' hea ...

  3. 雪碧图(background-position)、overflow、title中的小图标、光标、rgb 和opacity 与rgba

    一.background-position     雪碧图 我们的html和css中有三个属性可以向服务器发送请求:src   url    href 1.我们为什么使用雪碧图? 因为我们使用雪碧图之 ...

  4. Java递归调用改成非递归

          在java语言中,使用递归调用时,如果过多的调用容易造成java.lang.StackOverflowError即栈溢出和程序执行过慢.这是一个潜在Bug和影响程序执行效率问题,需要谨慎使 ...

  5. codevs 3070 寻找somebody4(水题日常)

     时间限制: 1 s  空间限制: 32000 KB  题目等级 : 黄金 Gold   题目描述 Description 有一天.....sb不见了,有个人要去找他..他发现sb在一个杨辉三角里.. ...

  6. 华为S3700交换机DHCP 配置

    1.设置交换机名称 system-view [Huawei]sysname dhcp01 [dhcp01] 2.配置管理IP [dhcp01]interface Vlanif 1 [dhcp01-Vl ...

  7. QT+常见控件+tab Widget 和Stacked Widget

    首先:这里介绍以下tab Widget 和Stacked Widget 之间的区别和使用的方法: tab Widget控件可以直接的进行切换,Stacked Widget却不可以直接在界面上进行切换, ...

  8. IIS实现HTTPS的主机名绑定

    默认情况下,IIS中HTTPS 绑定是无法指定主机名的解决办法:通过手工修改 IIS 配置来实现主机头绑定.打开如下位置的文件. C:\Windows\system32\inetsrv\config\ ...

  9. 「 Luogu P2420 」 让我们异或吧

    # 解题思路 两点之间的路径的话一定经过它们两个 LCA,这一点已经是显而易见的,那么再来看看异或的性质. $$a\ xor\ b\ xor\ b = a\\ a\ xor\ a=0\\ a\ xor ...

  10. 「 HDOJ P3887 」 Counting Offspring

    翻译 题目描述 给你一棵树,和它的树根 $P$,并且节点从 $1\rightarrow n$ 编号,现在定义 $f(i)$ 为 $i$ 的子树中,节点编号小于 $i$ 的节点的个数. 输入格式 有多组 ...