复(学)习化学时突然的一个 idea
期中考试成功探底。。。但是某些化学问题还是很有信息学价值的。。。
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的更多相关文章
- PHP进行数据库操作时遇到的一个问题
PHP进行数据库操作时遇到的一个问题 昨天在进行数据库操作时,遇到了一个问题(用的是 wampserver 环境): <?php $link = @mysqli_connect('localho ...
- Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们。
Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们. 这个是我将鸟哥书上的进行了一下整理的,希望不要涉及到版权问题. 1.显示日期的 ...
- 当我学完Python时我学了些什么
本文是本人学完Python后的一遍回顾,加深理解而已,Python大神请过~ 学习Python的这几天来,觉得Python还是比较简单,容易上手的,就基本语法而言,但是有些高级特性掌握起来还是有些难度 ...
- ios 仿新浪微博 UINavigationController 向左滑动时显示上一个控制器的View.
仿新浪微博 UINavigationController 向左滑动时显示上一个控制器的View. 实现原理,UINavigationController 的 self.view显示时把当前显示的vie ...
- L2TP连接尝试失败,因为安全层在初始化与远程计算机的协商时遇到了一个处理错误(转)
L2TP连接尝试失败,因为安全层在初始化与远程计算机的协商时遇到了一个处理错误 错误描述:“ L2TP连接尝试失败,因为安全层在初始化与远程计算机的协商时遇到了一个处理错误” 只有这个没有错误码. ...
- 启动多个eclipse 时,因为一个另一个启动报错,
启动多个eclipse 时,因为一个另一个启动报错, 原因: 可能是 有一个 eclipse 中 的 tomcat 配置出错:preference中 tomcat 配置 context dec ...
- json 数据类型,后台在组数据时,错一个标点符号,前端都解析不出来。
json 数据类型,后台在组数据时,错一个标点符号,前端都解析不出来.
- 在Hive中执行DDL之类的SQL语句时遇到的一个问题
在Hive中执行DDL之类的SQL语句时遇到的一个问题 作者:天齐 遇到的问题如下: hive> create table ehr_base(id string); FAILED: Execut ...
- 安装dede UTF_8时报出了一个致命错误和警告,最后不能显示网站后台和首页了
安装dede UTF_8时报出了一个致命错误和警告,最后不能显示网站后台和首页了.报错如下: 登陆首页显示:Fatal error: Call to undefined function ParCv( ...
随机推荐
- Linux常用命令awk
awk能够处理类似csv这种按行格式的数据,对每一行record按照-F指定的分隔符切割,然后处理.默认支持空格和\t分隔符 1.统计文件里某一列数据等于某个值的个数 -0_djt10.txt 2.拼 ...
- spring mvc URL忽略大小写
@Configuration public class SpringWebConfig extends WebMvcConfigurationSupport { @Override public vo ...
- hdu4003/蓝桥杯 金属采集
思路: 树形dp + 分组背包dp. 参考https://www.cnblogs.com/kuangbin/archive/2012/08/29/2661928.html 实现: #include & ...
- 【学习笔记】后端中的MVC和前端MVVM的关系
- 毕业设计:主界面(ViewPager + FragmentPagerAdapter)
一.主要思路 应用程序的主界面包含三个部分:顶部标题栏.底部标识栏和中间的内容部分.顶部标题栏内容基本不变,用于显示当前模块或者整个应用的名称:底部既能标识出当前Page,又能通过触发ImageBut ...
- 一个SAP开发人员的双截棍之路
由于种种原因,Jerry最近加入了SAP成都研究院的一个演讲俱乐部,这个俱乐部主要是提高大家的英语演讲能力. 说来Jerry也是大一下期和大二上期一次性高分通过四六级考试的,但是当毕业进入SAP成都研 ...
- Python matlab octave 矩阵运算基础
基础总结,分别在三种软件下,计算 求逆矩阵 矩阵转置 等运算,比较异同 例子:正规方程法求多元线性回归的最优解 θ=(XTX)-1XTY octave: pwd()当前目录 ones() zeros( ...
- 筛选法 || POJ 3292 Semi-prime H-numbers
5,9,13,……叫H-prime 一个数能且仅能由两个H-prime相乘得到,则为H-semi-prime 问1-n中的H-semi-prime有多少个 *解法:vis初始化为0代表H-prime, ...
- web前端中的一些注释表达法
1.HTML注释 <!--注释的内容--> 注释的地方(根据个人习惯可能有所不同): 结束标签的后面,这一切都是为了程序在嵌套的时候更加方便.明了,如: <div class=&qu ...
- vue的使用配置
我的编辑器是webstorm,虽然占内容占资源, 但是用起来很方便, 刚开始接触的时候就是用这个软件,很喜欢. vue的教程 1.http://www.jianshu.com/p/5ba253651c ...