HDU 1223 打表 + 大数
2024-08-28 20:24:23
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 ;
}
最新文章
- java发送email
- ajax实例2
- Java初学随笔
- 项目修改有感_主要是以js、Gridview为主
- mysql ALL_O_DIRECT引发的unaligned AIO/DIO导致hang
- Java错误:很奇怪的错误。。。
- [008]C---gcc环境下的一个编译器版本问题
- (转)php中GD库的配置,解决dedecms安装中GD不支持问题
- Maven--生命周期和插件(四)
- Android-----输入法的显示和隐藏
- python json数组对象排序
- echarts在tab切换时容器宽度设置为100%,只展示100px
- JAVA中几种常用的RPC框架介绍
- springcloud相关资料收集
- Python 动态加载并下载";梨视频";短视频
- yii2 使用多个数据库的案例
- 转--python -- 收发邮件
- SmokePing介绍
- 开发环境转Mac FAQ
- Business.Startup.Learning from Startup Mistakes at SpringSource