版本比较
题解:P12291 [蓝桥杯 2024 国 Java A] 粉刷匠小蓝
正文
增加 10 行删除 50 行
122456348910111256714891718191011121321141516171819202122239 行未改动33343536424344454647484950515253545556575859606162636465666768697071727374757677373839404115 行未改动# [P12291 粉刷匠小蓝](https://www.luogu.com.cn/problem/P12291)
## 题外话:
老师说:“~~老师什么都没说~~我的做法是假做法。”
~~老师说:“我的做法是假做法。”~~## 思路
### 我的思路是什么呢?
#### 找规律
我的思路是什么呢?### 找规律首先由题意可得:
- 当 $$ n = 1, a_1 = 1 $$ 时, 答案为 `1`- 当 $$ n = 2, a_1 = 1, a_2 = 1 $$ 时, 答案为 `1`- 当 $$ n = 2, a_1 = 1, a_2 = 1, a_3 = 1 $$ 时, 答案为 `2`- 当 $$ n = 2, a_1 = 1, a_2 = 1, a_3 = 1, a_4 = 1 $$ 时, 答案为 `4`- 当 $$ n = 2, a_1 = 1, a_2 = 1, a_3 = 1, a_4 = 1, a_5 = 1 $$ 时, 答案为 `12`- 当 $$ n = 3, a_1 = 1, a_2 = 1, a_3 = 1 $$ 时, 答案为 `2`- 当 $$ n = 4, a_1 = 1, a_2 = 1, a_3 = 1, a_4 = 1 $$ 时, 答案为 `4`- 当 $$ n = 5, a_1 = 1, a_2 = 1, a_3 = 1, a_4 = 1, a_5 = 1 $$ 时, 答案为 `12`
也许这时你就能跟我左边的~~大蛇~~一样,一眼看出规律 $$ f_i = f_{i - 1} \times \frac{i + 1}{2} \bmod (10 ^ 9 + 7) $$ 了。也许这时你就能跟我左边的~~大蛇~~一样,一眼看出规律 $$ f_i = f_{i - 1} \times \frac{i + 1}{2} \bmod 10 ^ 9 + 7 $$ 了(如果不行的话可以暴力打表试着多推几组哦)。
但是需要注意的是 $$ a_i = 0 $$ 时,对答案没有贡献,所以我们可以得出~~假做法~~正解了。
如果想深入了解,请左转至我的好朋友兼同学的 [题解](https://www.luogu.com.cn/article/fofi4y3d) 观看推导过程喵。
## 代码
```cpp#include <iostream>9 行未改动#include <map>#include <set>#include <cmath>
#define LOCAL#define int long longnamespace ly{ namespace IO{ #ifndef LOCAL constexpr auto maxn = 1 << 20; char in[maxn], out[maxn], *p1 = in, *p2 = in, *p3 = out; #define getchar() (p1 == p2 && (p2 = (p1 = in) + fread(in, 1, maxn, stdin), p1 == p2) ? EOF : *p1++) #define flush() (fwrite(out, 1, p3 - out, stdout)) #define putchar(x) (p3 == out + maxn && (flush(), p3 = out), *p3++ = (x)) class Flush{public: ~Flush(){flush();}}_; #endif namespace usr{ template <typename type> inline type read(type &x){x = 0; bool flag(0); char ch = getchar(); while(!isdigit(ch)) flag ^= ch == '-', ch = getchar(); while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return flag ? x = -x : x;} template <typename type> inline void write(type x){x < 0 ? x = -x, putchar('-') : 0; static short Stack[50], top(0); do Stack[++top] = x % 10, x /= 10; while(x); while(top) putchar(Stack[top--] | 48);} inline char read(char &x){do x = getchar(); while(isspace(x)); return x;} inline char write(const char &x){return putchar(x);} inline void read(char *x){static char ch; read(ch); do *(x++) = ch; while(!isspace(ch = getchar()) && ~ch);} template <typename type> inline void write(type *x){while(*x) putchar(*(x++));} inline void read(std::string &x){static char ch; read(ch), x.clear(); do x += ch; while(!isspace(ch = getchar()) && ~ch);} inline void write(const std::string &x){for(int i = 0, len = x.length(); i < len; ++i)putchar(x[i]);} template <typename type, typename...T> inline void read(type &x, T&...y){read(x), read(y...);} template <typename type, typename...T> inline void write(const type &x, const T&...y){write(x), putchar(' '), write(y...), sizeof...(y) ^ 1 ? 0 : putchar('\n');} template <typename type> inline void put(const type &x, bool flag = 0){write(x), flag ? putchar('\n') : putchar(' ');} } #ifndef LOCAL #undef getchar #undef flush #undef putchar #endif } using namespace IO::usr;} using namespace ly::IO::usr;// 已省略快读
constexpr int mod = 1e9 + 7;int f[1000005];signed main(){15 行未改动