蒟蒻疑惑
  • 板块P2193 HXY和序列
  • 楼主tongzt
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/11/28 20:20
  • 上次更新2024/11/28 21:48:39
查看原帖
蒟蒻疑惑
720865
tongzt楼主2024/11/28 20:20

为什么反向枚举会出现问题,大佬求助

#include <bits/stdc++.h>
using namespace std;

const int N = 2010, mod = 1e9 + 7;
int n, p;

int f[N][N];
vector<int> a;

void check(int x)
{
	for (int i = 1; i <= x / i; i++)
	{
		if (x % i == 0 && x / i != i)
		{
			a.push_back(i);
			a.push_back(x / i);
		}
		else a.push_back(i);
	}
}

int main()
{
	cin >> n >> p;
	
	for (int i = 1; i <= n; i++) f[1][i] = 1;
	
	for (int i = 2; i <= p; i++)
		for (int j = 1; j <= n; j++)
		{
			a.clear();
			check(j);
			int tmp = a.size();
			cout << tmp << endl;
			
			for (int k = 0; k < tmp; k++)
			{
				(f[i][j] += f[i - 1][j / a[k]]) %= mod;
				cout << f[i][j] << ' ' << i << ' ' << j << ' ' << k << endl;
			}
			cout << "!!!!" << endl;
		}
		
//	for (int i = 1; i <= p; i++)
//	{
//		for (int j = 1; j <= n; j++)
//			cout << f[i][j] << ' ';
//		cout << endl;
//	}

	int ans = 0;
	for (int i = 1; i <= n; i++) (ans += f[p][i]) %= mod;
	
	printf("%d\n", ans);
	return 0;
}

会多算

2024/11/28 20:20
加载中...