P1149
2024-09-03 02:59:43
这题不难,我写的一个复杂度 $ O(n^2) $ 的递归算法。。
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define index(a) (a - 'A')
#define transUpp(a) (a - 32)
#define transLow(a) (a + 32)
#define ll long long
#define PB push_back
int gcd(int a, int b){return b == 0 ? a : gcd(a%b, a);}
const int N = 782;
int num[N] = { 6,2,5,5,4,5,6,3,7,6 }, has[N][N];
int counts = 0;
void re(int n, int l1, int l2)
{
if (l1 + l2 < N)
{
has[l1][l2] = 1;
if (n == num[l1] + num[l2] + num[l1 + l2]) counts++;
if (!has[l1][l2 + 1]) re(n, l1, l2 + 1);
if (!has[l1 + 1][l2]) re(n, l1 + 1, l2);
}
}
int main()
{
// rep(i, 0, N) rep(j, 0, N) has[i][j] = 0; // 去掉这行初始化,投机优化一点速度
for (int k = 10; k < N; k++)
num[k] = num[k%10] + num[k/10];
int n;
cin >> n;
re(n - 4, 0, 0);
cout << counts << endl;
return 0;
}
最新文章
- BZOJ 4581: [Usaco2016 Open]Field Reduction
- URL编码:不同的操作系统、不同的浏览器、不同的网页字符集,将导致完全不同的编码结果。
- git学习相关资料
- Swift之UIBezierPath
- 1654 方程的解 - Wikioi
- windows mysql 中文乱码和中文录入提示太大错误的解决方法
- 2440裸 Delay(); 和 while(!(rUTRSTAT0 &;amp; 0x2)); 问题
- ZooKeeper概述
- CSS学习笔记一:css 画平面图形
- STL初始化initializer_list
- Hbase学习01
- Shell学习之Bash变量详解(二)
- swust oj 1015
- mysql awr v1.0.3修正说明以及发布
- kubernetes核心组件kube-proxy 学习总结
- openwrt git 代码下载地址
- jQuery表格列宽可变,兼容firfox
- Go语言中使用MySql数据库
- openvswitch BFD 简介
- linux下使用find命令根据系统时间查找文件用法