spoj 2319 BIGSEQ - Sequence

本文介绍了一种算法,用于将所有K位二进制数分为M个连续子序列,使得每个子序列中1的总数尽可能小。通过输入K和M,算法输出最小的最大子序列1的数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

You are given the sequence of all K-digit binary numbers: 0, 1,..., 2K-1. You need to fully partition the sequence into M chunks. Each chunk must be a consecutive subsequence of the original sequence. Let Si (1 ≤ i ≤ M) be the total number of 1's in all numbers in the ith chunk when written in binary, and let S be the maximum of all Si, i.e. the maximum number of 1's in any chunk. Your goal is to minimize S.

Input

In the first line of input, two numbers, K and M (1 ≤ K ≤ 100, 1 ≤ M ≤ 100, M ≤ 2^K), are given, separated by a single space character.

Output

In one line of the output, write the minimum S that can be obtained by some split. Write it without leading zeros. The result is not guaranteed to fit in a 64-bit integer.

Example

Input:

3 4

Output:

4

 

题解:

from 算法合集之《浅谈数位类统计问题》

code:

  1 #include<cstdio>
  2 #include<iostream>
  3 #include<cmath>
  4 #include<cstring>
  5 #include<algorithm>
  6 using namespace std;
  7 char ch;
  8 bool ok;
  9 void read(int &x){
 10     for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=1;
 11     for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
 12     if (ok) x=-x;
 13 }
 14 const int maxn=105;
 15 int k,n;
 16 const int MAXN=10;
 17 const int maxnum=10000;
 18 struct bignum{
 19     int len,v[MAXN];
 20     bignum(){memset(v,0,sizeof(v)),len=1;}
 21     bignum operator=(const char* num){
 22         memset(v,0,sizeof(v));
 23         len=((strlen(num)-1)>>2)+1;
 24         int j=1,k=0;
 25         for (int i=strlen(num)-1;i>=0;i--){
 26             if (j==maxnum) j=1,k++;
 27             v[k]+=(num[i]-'0')*j;
 28             j*=10;
 29         }
 30         return *this;
 31     }
 32     bignum operator=(const int num){
 33         char a[MAXN<<2];
 34         sprintf(a,"%d",num);
 35         *this=a;
 36         return *this;
 37     }
 38     bignum (int num){*this=num;}
 39     bignum (const char* num){*this=num;}
 40     bignum operator+(const bignum &a){
 41         bignum c;
 42         c.len=max(len,a.len);
 43         for (int i=0;i<c.len;i++){
 44             c.v[i]+=v[i]+a.v[i];
 45             if (c.v[i]>=maxnum) c.v[i+1]+=(c.v[i]/maxnum),c.v[i]%=maxnum;    
 46         }
 47         while (c.v[c.len]) c.len++;
 48         return c;
 49     }
 50     bignum operator-(const bignum b){
 51         bignum a,c;
 52         a=*this;
 53         c.len=len;
 54         for (int i=0;i<len;i++){
 55             if (a.v[i]<b.v[i]) a.v[i+1]--,a.v[i]+=maxnum;
 56             c.v[i]=a.v[i]-b.v[i];
 57         }    
 58         while (c.len>1&&!(c.v[c.len-1])) c.len--;
 59         return c;
 60     }
 61     bignum operator*(const bignum &a){
 62         bignum c;
 63         c.len=len+a.len;
 64         for (int i=0;i<len;i++)
 65             for (int j=0;j<a.len;j++){
 66                 c.v[i+j]+=v[i]*a.v[j];
 67                 if (c.v[i+j]>=maxnum) c.v[i+j+1]+=(c.v[i+j]/maxnum),c.v[i+j]%=maxnum;    
 68             }
 69         while (c.len>1&&!(c.v[c.len-1])) c.len--;
 70         return c;
 71     }
 72     bignum operator*(const int &a){
 73         bignum c=a;
 74         return *this*c;    
 75     }
 76     bignum operator/(const int &b){
 77         bignum c;
 78         int x=0;
 79         for (int i=len-1;i>=0;i--){
 80             c.v[i]=(x*maxnum+v[i])/b;
 81             x=(x*maxnum+v[i])%b;
 82         }
 83         c.len=len;
 84         while (c.len>1&&!(c.v[c.len-1])) c.len--;
 85         return c;
 86     }
 87     bignum operator+=(const bignum &a){*this=*this+a;return *this;}
 88     bignum operator-=(const bignum &a){*this=*this-a;return *this;}
 89     bignum operator*=(const bignum &a){*this=*this*a;return *this;}
 90     bignum operator/=(const int &a){*this=*this/a;return *this;}
 91     bool operator < (const bignum &x)const{
 92         if (len!=x.len) return len<x.len;
 93         for (int i=len-1;i>=0;i--)
 94             if (v[i]!=x.v[i]) return v[i]<x.v[i];
 95         return false;
 96     }
 97     bool operator > (const bignum &x)const{return x<*this;}
 98     bool operator <=(const bignum &x)const{return !(x<*this);}
 99     bool operator >=(const bignum &x)const{return !(*this<x);}
100     bool operator ==(const bignum &x)const{return !(x<*this||*this<x);}
101     bool operator !=(const bignum &x)const{return x<*this||*this<x;}
102 };    
103 void write(bignum x){
104     printf("%d",x.v[x.len-1]);
105     for (int i=x.len-2;i>=0;i--) printf("%0*d",4,x.v[i]);
106     puts("");
107 }
108 void read(bignum &x){
109     static char num[MAXN<<2];
110     scanf("%s",num);
111     x=num;
112 }
113 bignum l,r,m,pw2[maxn],sum[maxn],tmp,res,t,xx;
114 int a[maxn];
115 void init(){
116     pw2[0]=1;
117     for (int i=1;i<=101;i++) pw2[i]=pw2[i-1]*2;
118     sum[0]=0;
119     for (int i=1;i<=101;i++) sum[i]=sum[i-1]*2+pw2[i-1];
120 }
121 void calc(){
122     tmp=1,res=0;
123     for (int i=1;i<=k;i++) if (a[i]) res+=tmp+sum[i-1],tmp+=pw2[i-1];
124 }
125 void find(bignum lim){
126     bool flag=(lim>=sum[k]);
127     int tmp=0;
128     for (int i=k;i>=1;i--){
129         xx=sum[i-1]+pw2[i-1]*tmp;
130         if (lim>=xx) lim=lim-xx,tmp++,a[i]=1;
131         else a[i]=0;
132     }
133     if (!flag){
134         for (int i=1;i<=k;i++){
135             a[i]^=1;
136             if (!a[i]) break;
137         }
138     }
139 }
140 bool check(){
141     for (int i=1;i<=k;i++) if (!a[i]) return false;
142     return true;
143 }
144 bool check(bignum lim){
145     bignum t=0;
146     int cnt=n;
147     memset(a,0,sizeof(a));
148     while (cnt--){
149         find(t+lim),calc(),t=res;
150         if (check()) return true;
151     }
152     return false;
153 }
154 int main(){
155     init();
156     read(k),read(n);
157     l=1,r=sum[k];
158     while (l!=r){
159         m=(l+r)/2;
160         if (check(m)) r=m; else l=m+1;
161     }
162     write(l);
163     return 0;
164 }

 

转载于:https://www.cnblogs.com/chenyushuo/p/5239840.html

内容概要:本文详细探讨了基于MATLAB/SIMULINK的多载波无线通信系统仿真及性能分析,重点研究了以OFDM为代表的多载波技术。文章首先介绍了OFDM的基本原理和系统组成,随后通过仿真平台分析了不同调制方式的抗干扰性能、信道估计算法对系统性能的影响以及同步技术的实现与分析。文中提供了详细的MATLAB代码实现,涵盖OFDM系统的基本仿真、信道估计算法比较、同步算法实现和不同调制方式的性能比较。此外,还讨论了信道特征、OFDM关键技术、信道估计、同步技术和系统级仿真架构,并提出了未来的改进方向,如深度学习增强、混合波形设计和硬件加速方案。; 适合人群:具备无线通信基础知识,尤其是对OFDM技术有一定了解的研究人员和技术人员;从事无线通信系统设计与开发的工程师;高校通信工程专业的高年级本科生和研究生。; 使用场景及目标:①理解OFDM系统的工作原理及其在多径信道环境下的性能表现;②掌握MATLAB/SIMULINK在无线通信系统仿真中的应用;③评估不同调制方式、信道估计算法和同步算法的优劣;④为实际OFDM系统的设计和优化提供理论依据和技术支持。; 其他说明:本文不仅提供了详细的理论分析,还附带了大量的MATLAB代码示例,便于读者动手实践。建议读者在学习过程中结合代码进行调试和实验,以加深对OFDM技术的理解。此外,文中还涉及了一些最新的研究方向和技术趋势,如AI增强和毫米波通信,为读者提供了更广阔的视野。
管理员功能需求 用户管理 查看用户列表:显示所有用户基本信息 添加用户:支持输入新用户信息并保存至数据库 修改用户信息:支持选择用户并更新其信息 删除用户:支持从数据库中删除选定用户 实习报告成绩管理 查看实习报告列表:显示所有学生实习报告 批阅实习报告:支持选择报告并给出批阅意见和评分 查看实习成绩列表:显示所有学生实习成绩 录入实习成绩:支持选择学生并输入成绩 修改实习成绩:支持更新学生实习成绩 通知公告管理 发布通知公告:支持输入通知内容并发布至系统 管理通知公告:支持查看、编辑和删除已发布通知 教师功能需求 学生管理 查看所指导学生列表:显示教师负责的所有学生 查看学生实习情况:支持查看学生实习岗位、日志、报告等 实习报告批阅成绩录入 查看待批阅报告列表:显示教师待批阅的实习报告 批阅报告:支持选择报告并给出批阅意见和评分 通知公告查看 查看系统通知公告:显示系统发布的所有通知和公告 实习岗位管理 发布实习岗位:支持输入岗位信息并发布至系统 编辑实习岗位:支持更新已发布岗位信息 删除实习岗位:支持从系统中删除选定岗位 学生功能需求 个人信息管理 查看个人信息:显示学生基本信息 修改个人信息:支持更新学生信息 实习岗位查询与申请 查询实习岗位:显示所有可用实习岗位 申请实习岗位:支持选择岗位并提交申请 实习日志提交 提交实习日志:支持输入日志内容并提交至系统 查看实习日志:显示学生提交的实习日志 实习报告提交 提交实习报告:支持输入报告内容并提交至系统 查看实习报告:显示学生报告及批阅意见 通知公告查看 查看系统通知公告:显示系统发布的所有通知和公告
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值