NOIP T2 50pts 做法全部 TLE 了求助
  • 板块学术版
  • 楼主_jhq
  • 当前回复3
  • 已保存回复3
  • 发布时间2021/11/20 19:55
  • 上次更新2023/11/3 23:56:31
查看原帖
NOIP T2 50pts 做法全部 TLE 了求助
178910
_jhq楼主2021/11/20 19:55

RT,在洛谷上民间数据交了好几次都是,所有的测试点全部都 TLE 了,但是我写的是 O(n2m2m)O(n^2m2^m) 做法没有发现问题,freopen 我也已经注释了,本机上造了几个数据 m=12m=12 的大约 0.5s 就能跑出答案,感觉不会 TLE 啊,求助。

代码:

#include <iostream>
#include <cstdio>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define space putchar(' ');
#define enter putchar('\n');
#define debug(x) cerr << #x << " = " << x << endl;
using namespace std;

namespace Fast
{
	template<typename T> inline void read(T &s)
	{
		s = 0; bool f = false; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = true; c = getchar(); }
		while (c >= '0' && c <= '9') s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
		if (f) s = ~s + 1;
	}
	template<typename T, typename... Args> inline void read(T &x, Args&... others)
	{
		read(x), read(others...);
	}
	template<typename T> inline T Abs(T x) { return x < 0 ? -x : x; }
	template<typename T> inline T Max(T x, T y) { return x > y ? x : y; }
	template<typename T> inline T Min(T x, T y) { return x < y ? x : y; }
	template<typename T> inline T addmod(T &x, T p) { if (x >= p) x -= p; }
}
using namespace Fast;

const ll p = 998244353;
ll v[105], f[35][1 << 17];

int main()
{
//	freopen("sequence.in", "r", stdin);
//	freopen("sequence.out", "w", stdout);
	int n, m, k; read(n, m, k); ll ans = 0;
	for (int i = 0; i <= m; i++) read(v[i]); f[0][0] = 1;
	for (int i = 0; i < n; i++)
		for (int j = 0; j <= i * (1 << m); j++)
			for (int l = 0; l <= m; l++)
				addmod(f[i + 1][j + (1 << l)] += f[i][j] * v[l] % p, p);
	for (int i = 0; i <= n * (1 << m); i++)
		if (__builtin_popcount(i) <= k) addmod(ans += f[n][i], p);
	cout << ans % p;
	return 0;
}
2021/11/20 19:55
加载中...