求助,为啥会T
查看原帖
求助,为啥会T
489257
Mirage_Insane楼主2022/11/18 21:05

感觉不能再优化了,快读快写优化不大吧,T了70分

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
#define SF scanf
#define PF printf
int a[125], dp[125][125];
int dfs(int pos, bool lead, bool limit, int op) {
	if(pos < 0) return op >= 50;
	if(!limit && !lead && dp[pos][op] != -1) return dp[pos][op];
	int up = limit ? a[pos] : 1;
	int ans = 0;
	for(int i = 0; i <= up; i++) ans += dfs(pos - 1, lead || i, limit && (i == up), op + (lead || i ? (i == 0 ? 1 : -1) : 0));
	if(!limit && !lead) dp[pos][op] = ans;
	return ans;
}
int main() {
	memset(dp, -1, sizeof(dp));
	int x, y;
	SF("%d%d", &x, &y);
	int len = 0;
	x--;
	while(x != 0ll) a[len++] = x & 1, x >>= 1;
	int ans1 = dfs(len - 1, false, true, 50);
	len = 0;
	while(y != 0ll) a[len++] = y & 1, y >>= 1;
	int ans2 = dfs(len - 1, false, true, 50);
	PF("%d", ans2 - ans1);
	return 0;
}
2022/11/18 21:05
加载中...