http://acm.hdu.edu.cn/showproblem.php?pid=1223

一般遇到这些题,我都是暴力输出前几项,找规律。未果。

然后输出n = 1时候,以A开始,有多少个答案,

n = 2的时候,A开始,B开始,有多少个答案。然后发现了规律。大数之

const int maxn =  + ;
struct node {
int val;
int id;
bool operator < (const struct node & rhs) const {
if (val != rhs.val) return val < rhs.val;
else return id < rhs.id;
}
}a[maxn];
int n;
int f[maxn];
int lena;
map<string, bool>mp;
int aa;
void dfs(int cur) {
if (cur == n + ) {
for (int i = ; i <= n; ++i) {
a[i].val = f[i];
a[i].id = i;
}
sort(a + , a + + n);
string s;
s += 'A' + a[].id - ;
for (int i = ; i <= n; ++i) {
if (a[i].val == a[i - ].val) {
s += "=";
} else s += "<";
s += 'A' + a[i].id - ;
}
if (mp[s]) return;
if (s[] == 'C') {
cout << s << endl;
aa++;
}
mp[s] = true;
return;
}
for (int i = ; i <= n; ++i) {
f[cur] = i;
dfs(cur + );
}
}
void work() {
n = ;
dfs();
cout << mp.size() << endl;
cout << aa << endl;
}

dfs打表

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <iomanip>
const int maxn = + ;
void bigadd (char str1[],char str2[],char str3[]) { //str1 + str2 = str3
int len1=strlen(str1+),len2=strlen(str2+);
char b[maxn]= {};
int i=len1,j=len2;
int h=;
while (i>= && j>=) b[h++] = str1[i--]-'' + str2[j--]-'';
while (i>=) b[h++] = str1[i--]-'';
while (j>=) b[h++] = str2[j--]-'';
for (int i=; i<h; i++) { //h是理论越界的
if (b[i] >= ) {
b[i+]++;
b[i] -= ;
}
}
if (!b[h]) --h;//没有进位到越界位。
int t=h;
for (int i=; i<=h; i++) str3[t--]=b[i]+'';
str3[h+]='\0'; //一定要手动添加结束符,不然会GG
return ;
}
char a[maxn][maxn][maxn];
char last[maxn];
char t[maxn];
void init() {
// a[1][1] = 1.0;
strcpy(a[][] + , "");
// long double last = 1.0;
strcpy(last + , "");
for (int j = ; j <= ; ++j) {
// a[j][j] = last;
strcpy(a[j][j] + , last + );
// printf("%s\n", a[j][j] + 1);
for (int i = j - ; i >= ; --i) {
// a[i][j] = a[i + 1][j] + a[i][j - 1];
bigadd(a[i + ][j], a[i][j - ], a[i][j]);
// printf("%s\n", a[i][j] + 1);
}
// last = 0;
memset(t, , sizeof t);
for (int k = j; k >= ; --k) {
// last += a[k][j];
bigadd(a[k][j], t, last);
strcpy(t + , last + );
}
}
}
void work() {
int n;
scanf("%d", &n);
printf("%s\n", a[n + ][n + ] + );
}
int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
init();
int t;
scanf("%d", &t);
while (t--) work();
return ;
}

HDU 1223 打表 + 大数的更多相关文章

  1. HDU 5047 Sawtooth(大数优化+递推公式)

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 题目大意: 给n条样子像“m”的折线,求它们能把二维平面分成的面最多是多少. 解题思路: 我们发现直线1条 ...

  2. Buy the Ticket HDU 1133 递推+大数

    题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目大意: 有m+n个人去买电影票,每张电影票50元,  m个人是只有50元一张的,  n个人 ...

  3. Children’s Queue HDU 1297 递推+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...

  4. Heron and His Triangle HDU - 6222(pell 大数)

    ---恢复内容开始--- Heron and His Triangle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/2 ...

  5. hdu 4542 打表+含k个约数最小数

    http://acm.hdu.edu.cn/showproblem.php?pid=4542 给出一个数K和两个操作 如果操作是0,就求出一个最小的正整数X,满足X的约数个数为K. 如果操作是1,就求 ...

  6. HDU 5666 Segment 数论+大数

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5666 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  7. HDU 1018Big Number(大数的阶乘的位数,利用公式)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1018 Big Number Time Limit: 2000/1000 MS (Java/Others) ...

  8. hdu 4068 I-number【大数】

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4608 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  9. HDU 1047 Integer Inquiry 大数相加 string解法

    本题就是大数相加,题目都不用看了. 只是注意的就是HDU的肯爹输出,好几次presentation error了. 还有个特殊情况,就是会有空数据的输入case. #include <stdio ...

随机推荐

  1. Shell hook

    [目的]实现 ll -as   +hook+     clear Shell脚本及钩子 - CSDN博客 https://blog.csdn.net/shengzhu1/article/details ...

  2. Serialization and deserialization are bottlenecks in parallel and distributed computing, especially in machine learning applications with large objects and large quantities of data.

    Serialization and deserialization are bottlenecks in parallel and distributed computing, especially ...

  3. firefox 45 版本

    在做项目的时候,发现45版本的firefox浏览器.声明函数要放在调用者的上方.而firefox的47,48版本则没有这种情况发生.

  4. Linux搭建lnmp环境

    在CentOS 6上使用yum安装lnmp服务,原文链接http://www.qiansw.com/yum-lnmp.html

  5. String常量池

    http://developer.51cto.com/art/201106/266454.htm

  6. 修改DEDE系统数据库表前缀

    1,修改之前我们先备份下数据(哥们儿之前没有备份,我艹,害苦了),备份的操作过程是:网站后台------系统------数据库备份/还原-------然后按提交.默认保存的数据在data/backup ...

  7. C++ set和map的简单使用

    C++中的STL模板库的功能可谓相当强大.今天我们来简单说一下set和map的使用方法. 1.pair 我们先来说一下pair.pair定义在头文件<utility>中,其本身相当于一个已 ...

  8. node --save可以省略掉手动修改package.json的步骤

    当你为你的模块安装一个依赖模块时,正常情况下你得先安装他们(在模块根目录下npm install module-name),然后连同版本号手动将他们添加到模块配置文件package.json中的依赖里 ...

  9. lua 与C通过c api传递table (2)

    本文转自http://blog.csdn.net/a_asinceo/article/details/49907903(感谢...) 一.单个参数的传递 首先我们在Lua中注册一个C类PJYCallb ...

  10. 如何升级xcode 中的cocos2dx 到v2.2.2以上版本

    每次升级cocos2dx版本都觉得不知道怎么弄才行. 这次升级到v2.2.2版本又花了我不少时间.因此在这里分享一下,以后也有地方可以查询. 1. 到http://cocos2d-x.org/ 下载最 ...