# 12678 - Count 1s >author: Utin ###### tags: `dynamic program` --- ## Brief 建表 ## Solution 0 ```c= #include <stdio.h> int dp[1000005]; int main() { int N, tail = 1; scanf("%d", &N); while (N--) { int a, b; scanf("%d %d", &a, &b); for (int i = tail; i <= b; i++) { int tmp = i, amount = 0; while (tmp > 0) { if (tmp % 10 == 1) amount++; tmp /= 10; } dp[i] = dp[i-1] + amount; } if (tail < b + 1) tail = b + 1; printf("%d\n", dp[b] - dp[a-1]); } } // Utin ``` ## Reference
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up