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. app发布流程

    在app上架之前做两件事(instruments,profile): 1.代码静态分析:不用运行程序,直接检测代码有没有潜在的一些内存泄漏 2.动态分析:a l loctions/leaks 内存溢出 ...

  2. Client should know only resource URIs and that’s all.

    REST Principles and Architectural Constraints – REST API Tutorial https://restfulapi.net/rest-archit ...

  3. 正则_action

    http://wiki.ubuntu.org.cn/index.php?title=Python%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%93% ...

  4. IOS中UIActionSheet使用方法详解

    一.初始化方法 - (instancetype)initWithTitle:(NSString *)title delegate:(id<UIActionSheetDelegate>)de ...

  5. YTU 2444: C++习题 对象转换

    2444: C++习题 对象转换 时间限制: 1 Sec  内存限制: 128 MB 提交: 914  解决: 581 题目描述 定义一个Teacher(教师)类(教师号,姓名,性别,薪金)和一个St ...

  6. codeforces A. Kitahara Haruki's Gift 解题报告

    题目链接:http://codeforces.com/problemset/problem/433/A 题目意思:给定 n 个只由100和200组成的数,问能不能分成均等的两份. 题目其实不难,要考虑 ...

  7. 四叉树 bnuoj

    点击打开题目链接 建树+广搜一棵树:最下面有更短代码(很巧妙). #include<iostream> #include<stdio.h> #include<queue& ...

  8. SPOJ:Dandiya Night and Violence(Bitset优化)

    It is Dandiya Night! A certain way how dandiya is played is described: There are N pairs of people p ...

  9. BZOJ_2225_[Spoj 2371]Another Longest Increasing_CDQ 分治+树状数组

    BZOJ_2225_[Spoj 2371]Another Longest Increasing_CDQ 分治+树状数组 Description        给定N个数对(xi, yi),求最长上升子 ...

  10. [SHOI 2012] 魔法树

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2836 [算法] 树链剖分 时间复杂度 : O(NlogN ^ 2) [代码] #in ...