IOS #define 的用法

本文介绍了在编程中如何使用预处理器指令定义常量及函数宏。具体包括了一个整数常量kBUTTONWEIGHT的定义及其值为40,以及一个用于获取指定大小字体的函数宏kGETFONT。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


定义常量:

<span style="font-size:18px;">#define kBUTTONWEIGHT 40;</span>

函数宏:

<span style="font-size:18px;">#define kGETFONT(x) [UIFont systemFontOfSize:x];</span>



D、马騳骉子序列 题目描述 有一个长度为 的序列 ,请求出 中有多少个马騳骉子序列。 一个序列 被定义为马騳骉序列,当且仅当:对于序列中每一个位置 , 都能够被 整除 由于答案可能过大,所以对 取模 输入描述 第一行输入一个整数 第二行输入 个整数表示序列 输出描述 输出一个整数表示答案。 输入样例 输出样例 样例解释 样例中的13种方案分别为 D、马騳骉的子序列 首先考虑暴力动态规划,设置状态 dp[i][j] 为枚举到 i 点,b序列长度为 j 的方案个数。 则状态转移方程为: dp[i][j] = dp[i-1][j] + (a[i] % j == 0) * dp[i-1][j-1] 但是这样显然会空间超限,考虑如何优化。 我们发现dp[i][j],只会由dp[i-1] 转移来。 所以可以通过滚动数组优化掉第一维。 且第二维 j 的更新只与前面的有关,所以可以通过倒着枚举优化。 即:用dp[j]表示枚举到目前为止,长度为j的合法序列的数量。 #include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <vector> #define CLOSE ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define isd(c) ('0' <= (c) && (c) <= '9') #define isa(c) ('a' <= (c) && (c) <= 'z') #define isA(c) ('A' <= (c) && (c) <= 'Z') #define mem(a, b) memset(a, b, sizeof a); #define N 100005 #define M 2000005 #define mod 1000000007 #define inf 0x3f3f3f3f #define infll 0x3f3f3f3f3f3f3f3f #define ll long long #define ull unsigned long long #define PI acos(-1) #define endl "\n" #define pii pair<int, int> #define F first #define S second #define bug cout << endl << " .....here!...." << endl; //#pragma GCC optimize("O3") //#define Time ((double)clock() / CLOCKS_PER_SEC <= 0.95) using namespace std; using namespace __gnu_cxx; using namespace __gnu_pbds; ll dp[M], num[M]; int main() { CLOSE int n; cin >> n; dp[0] = 1; for (int i = 1; i <= n; i++) { int x, cnt = 0; cin >> x; for (int j = 1; j * j <= x; j++) { if (x % j == 0) { num[++cnt] = j; if (x / j != j) num[++cnt] = x / j; } } sort(num + 1, num + 1 + cnt, greater<int>()); for (int j = 1; j <= cnt; j++) dp[num[j]] = (dp[num[j]] + dp[num[j] - 1]) % mod; } ll ans = 0; for (int i = 1; i <= n; i++) ans = (ans + dp[i]) % mod; cout << ans << endl; return 0; } 我是一个算竞小白,dp新手,请你为我详细讲解这道题目,我看不懂
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值