acdream 1154 Lowbit Sum

先贴代码,以后再写题解。。。

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <algorithm>
 5 using namespace std;
 6
 7 typedef long long ll;
 8
 9 ll s[100];
10
11 ll init (int n){
12     if (s[n])
13         return s[n];
14     s[n]=init (n-1)*2-(1<<(n-1))+(1<<n);//cout<<s[n]<<" ";
15     return s[n];
16 }
17
18 int main (){
19     int n;    //while (cin>>n&&n) cout<<(1024>>n)<<endl;
20     ll ans=1;
21     int temp=2;
22     memset (s,0,sizeof s);
23     s[0]=1;
24     init (30);    //for (int i=0;i<=30;i++) cout<<s[i]<<" ";
25     while (~scanf ("%d",&n)){
26         ans=0;
27         for (int i=0;n&&i<30;i++) {
28             if (n&1)
29                 ans+=s[i];//cout<<ans<<endl;
30             n>>=1;
31             //n/=2;
32         }
33         printf ("%lld\n",ans);
34     }
35     return 0;
36 }

acdream 1154 Lowbit Sum

时间: 2024-12-25 20:44:06

acdream 1154 Lowbit Sum的相关文章

ACdream 1154 Lowbit Sum (数位DP)

Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description long long ans = 0; for(int i = 1; i <= n; i ++) ans += lowbit(i) lowbit(i)的意思是将i转化成二进制数之后,只保留最低位的1及其后面的0,截断前面的内容,然后再转成10进制数 比

ACdreamOJ 1154 Lowbit Sum (数位dp)

ACdreamOJ 1154 Lowbit Sum (数位dp) ACM 题目地址:ACdreamOJ 1154 题意: long long ans = 0; for(int i = 1; i <= n; i ++) ans += lowbit(i) lowbit(i)的意思是将i转化成二进制数之后,只保留最低位的1及其后面的0,截断前面的内容,然后再转成10进制数.即lowbit(i) = i&(-i). 每输入一个n,求ans 分析: 用二进制去考虑,可以发现这是个数位dp,如果当前第i

ACDream - Lowbit Sum

先上题目: C - Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description long long ans = 0;for(int i = 1; i <= n; i ++)    ans += lowbit(i)lowbit(i)的意思是将i转化成二进制数之后,只保留最低位的1及其后面的0,截断前面的内容,然

Lowbit Sum 规律

Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description long long ans = 0;for(int i = 1; i <= n; i ++)    ans += lowbit(i)lowbit(i)的意思是将i转化成二进制数之后,只保留最低位的1及其后面的0,截断前面的内容,然后再转成10进制数比

Acdream 1171 Matrix sum 上下界费用流

题目链接:点击打开链接 Matrix sum Time Limit: 8000/4000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitStatisticNext Problem Problem Description sweet和zero在玩矩阵游戏,sweet画了一个N * M的矩阵,矩阵的每个格子有一个整数.zero给出N个数Ki,和M个数Kj,zero要求sweet选出一些数,满足从第 i 行至少选出了Ki

ACdream 1148 GCD SUM (久违的莫比乌斯)

题目链接 题意:给出N,M 执行如下程序: long long  ans = 0,ansx = 0,ansy = 0; for(int i = 1; i <= N; i ++) for(int j = 1; j <= M; j ++) if(gcd(i,j) == 1) ans ++,ansx += i,ansy += j; cout << ans << " " << ansx << " " <<

acdream 1148 GCD SUM 莫比乌斯反演 ansx,ansy

GCD SUM Time Limit: 8000/4000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitStatisticNext Problem Problem Description 给出N,M执行如下程序:long long  ans = 0,ansx = 0,ansy = 0;for(int i = 1; i <= N; i ++)   for(int j = 1; j <= M; j ++)     

[补档]noip2019集训测试赛(八)

Problem B: 2048 Special Judge Time Limit: 1000 ms Memory Limit: 256 MB Description 2048曾经是一款风靡全球的小游戏. 今天,我们换一种方式来玩这个小游戏. 现在,你有一个双端队列,你只能把元素从左端或从右端放入双端队列中.一旦放入就不得取出.放入后,若队列中有连续两个相同的元素,它们将自动合并变成一个新的元素--原来那两个元素的和.若新的元素与它相邻的元素相同,则继续合并-- 如:双端队列中有2, 4, 16三

ACDream - Divide Sum

先上题目: Divide Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description long long ans = 0;for(int i = 1; i <= n; i ++)    for(int j = 1; j <= n; j ++)        ans += a[i] / a[j];给出n,a[1]...a[