HDU 1223 打表 + 大数
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 打表 + 大数的更多相关文章
- HDU 5047 Sawtooth(大数优化+递推公式)
http://acm.hdu.edu.cn/showproblem.php?pid=5047 题目大意: 给n条样子像“m”的折线,求它们能把二维平面分成的面最多是多少. 解题思路: 我们发现直线1条 ...
- Buy the Ticket HDU 1133 递推+大数
题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目大意: 有m+n个人去买电影票,每张电影票50元, m个人是只有50元一张的, n个人 ...
- Children’s Queue HDU 1297 递推+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...
- Heron and His Triangle HDU - 6222(pell 大数)
---恢复内容开始--- Heron and His Triangle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/2 ...
- hdu 4542 打表+含k个约数最小数
http://acm.hdu.edu.cn/showproblem.php?pid=4542 给出一个数K和两个操作 如果操作是0,就求出一个最小的正整数X,满足X的约数个数为K. 如果操作是1,就求 ...
- HDU 5666 Segment 数论+大数
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5666 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- HDU 1018Big Number(大数的阶乘的位数,利用公式)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1018 Big Number Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 4068 I-number【大数】
题目: http://acm.hdu.edu.cn/showproblem.php?pid=4608 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 1047 Integer Inquiry 大数相加 string解法
本题就是大数相加,题目都不用看了. 只是注意的就是HDU的肯爹输出,好几次presentation error了. 还有个特殊情况,就是会有空数据的输入case. #include <stdio ...
随机推荐
- 【POJ3740】Easy Finding DLX(Dancing Links)精确覆盖问题
题意:多组数据,每组数据给你几行数,要求选出当中几行.使得每一列都有且仅有一个1.询问是可不可行,或者说能不能找出来. 题解:1.暴搜.2.DLX(Dancing links). 本文写的是DLX. ...
- FZU1686 神龙的难题 —— Dancing Links 可重复覆盖
题目链接:https://vjudge.net/problem/FZU-1686 Problem 1686 神龙的难题 Accept: 812 Submit: 2394 Time Limit: ...
- YTU 2878: 结构体--学生信息排序
2878: 结构体--学生信息排序 时间限制: 1 Sec 内存限制: 128 MB 提交: 297 解决: 148 题目描述 定义存放一个学生信息的结构体类型,学生信息包括:姓名,学号,性别,院 ...
- 计算机学院大学生程序设计竞赛(2015’12)01 Matrix
01 Matrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- html5--3.1 form元素
html5--3.1 form元素 学习要点 form元素及其属性 form元素 用来定义一个表单,是建立表单的基础元素,(就类似定义表格的table) 表单的其他元素包含在form元素中,其主要子元 ...
- UVA-11462 (计数排序)
题意: 2e6个数,按从小到大的顺序输出; 思路: 计数排序; AC代码: #include <bits/stdc++.h> /* #include <vector> #inc ...
- bzoj1783
博弈论+dp 从未做过博弈论... 思路是这样的,我们倒着考虑,分别设f[i]表示先手选了a[i]后能取得的最大值,g[i]表示先手取了a[i]后后手能获得的最大值 g[i]=f[mx],f[mx]是 ...
- MFC程序中的 _T("") 什么意思?
_T("")就是把引号内的字符串转换为宽字节的Unicode编码 宽字节就是unicode.
- C++ 动态多维数组的申请与释放
今天在实验室的项目中遇到了一个问题,直接上代码: void ViBe::init(Mat img) { imgcol = img.cols; imgrow = img.rows; // 动态分配三维数 ...
- [Vue 牛刀小试]:第十二章 - 使用 Vue Router 实现 Vue 中的前端路由控制
一.前言 前端路由是什么?如果你之前从事的是后端的工作,或者虽然有接触前端,但是并没有使用到单页面应用的话,这个概念对你来说还是会很陌生的.那么,为什么会在单页面应用中存在这么一个概念,以及,前端路由 ...