UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209956#3781. 减法编码zhuangmingyi100569ms1260kbC++111.0kb2024-08-05 11:58:292024-08-05 12:21:32

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
string s[15];
int cnt[15], tmp;
ll ksm(ll x, ll y)
{
	ll ans = 1;
	while (y)
	{
		if (y & 1) ans = ans * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return ans;
}
string jian(string x)
{
	int u = x.size() - 1;
	while (x[u] != '1')
	{
		x[u] = '1';
		tmp++;
		u--;
	}
	tmp--;
	x[u]--;
	return x;
}
void dfs(int x)
{
	if (x == 11) return;
	s[x] = s[x - 1] + jian(s[x - 1]);
	for (int i = 0;  i < s[x].size(); ++i) 
	{
		if (s[x][i] == '1') cnt[x]++;
	}
	dfs(x + 1);
}
int main()
{
	s[0] = "1";
	dfs(1);
	int n;
	cin >> n;
	if (n <= 10) cout << cnt[n] << endl;
	else
	{
		int ans = cnt[10], Temp = n - 10, lst = cnt[10];
		tmp = cnt[10];
		string temp = s[10];
		ans %= mod;
		while (Temp--)
		{
			ans *= 2;
			ans -= lst;
			temp = jian(temp);
			//cout << ans << endl;
			//cout << tmp << endl;
			ans += tmp;
			ans %= mod;
			//cout << ans << endl;
			lst = tmp;
		}
		cout << ans << endl;
	}
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1256kb

input:

5

output:

15

result:

ok "15"

Test #2:

score: 10
Accepted
time: 0ms
memory: 1252kb

input:

6

output:

30

result:

ok "30"

Test #3:

score: 10
Accepted
time: 0ms
memory: 1256kb

input:

18

output:

121370

result:

ok "121370"

Test #4:

score: 10
Accepted
time: 0ms
memory: 1256kb

input:

12

output:

1897

result:

ok "1897"

Test #5:

score: 10
Accepted
time: 0ms
memory: 1256kb

input:

19

output:

242739

result:

ok "242739"

Test #6:

score: 10
Accepted
time: 0ms
memory: 1260kb

input:

20

output:

485480

result:

ok "485480"

Test #7:

score: 10
Accepted
time: 102ms
memory: 1260kb

input:

504001

output:

473521215

result:

ok "473521215"

Test #8:

score: 10
Accepted
time: 40ms
memory: 1260kb

input:

204333

output:

225845124

result:

ok "225845124"

Test #9:

score: 10
Accepted
time: 213ms
memory: 1256kb

input:

991353

output:

448279491

result:

ok "448279491"

Test #10:

score: 10
Accepted
time: 214ms
memory: 1260kb

input:

999999

output:

525011380

result:

ok "525011380"

Extra Test:

score: 0
Extra Test Passed