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 ;
}

最新文章

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

热门文章

  1. kbmMemTable关于内存表的使用,以及各种三层框架的评价
  2. String bulit-in function
  3. Python之如果添加扩展包
  4. C/C++ 编译器优化
  5. Objective-C Runtime(二)消息传递机制
  6. PDB文件说明
  7. 微信小程序服务类目大坑:特殊行业服务类目所需资质材料
  8. ASP.NET Core:template
  9. DC 兼容的DC
  10. [技术分享]利用MSBuild制作msf免杀的后门