欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > 【洛谷】AT_abc178_d [ABC178D] Redistribution 的题解

【洛谷】AT_abc178_d [ABC178D] Redistribution 的题解

2025/8/7 23:46:33 来源:https://blog.csdn.net/ZH_qaq/article/details/142578607  浏览:    关键词:【洛谷】AT_abc178_d [ABC178D] Redistribution 的题解

【洛谷】AT_abc178_d [ABC178D] Redistribution 的题解

洛谷传送门

AT传送门

题解

一个水水的动态规划,阿巴巴巴。

题目大概是这样:

给定一个正整数 S S S,问有多少个数满足以下条件:

  • 序列中不能出现小于 3 3 3 的正整数。

  • 序列中的和必须等于输入的 S S S

这是一道求方案数的题,我们可以用动态规划来做,那么我们就可以定义 d p i dp_i dpi 为和为 i i i
时的方案数,然后我们就可以想到对于每一个 d p i dp_i dpi 它都等于从
i − 3 i−3 i3 3 3 3 的方案数总和加一,最后输出 f n f_n fn 即可。

最后提醒,AtCoder 输出要换行!!!

代码

#include <bits/stdc++.h>
#define lowbit(x) x & (-x)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
namespace fastIO {inline int read() {register int x = 0, f = 1;register char c = getchar();while (c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();return x * f;}inline void write(int x) {if(x < 0) putchar('-'), x = -x;if(x > 9) write(x / 10);putchar(x % 10 + '0');return;}
}
using namespace fastIO;
int n;
ll f[2005];
int main() {//freopen(".in","r",stdin);//freopen(".out","w",stdout);ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);n = read();for(int i = 3; i <= n; i ++) {f[i] = 1;for(int j = 3; j <= i - 3; j ++) {f[i] = (f[i] + f[j]) % mod;}	}cout << f[n] << endl;return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词