【洛谷】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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值