我想对斐波那契位序列进行排名(将位序列映射为数字)并取消排名(对位序列进行映射)。
什么是斐波那契位序列?
每个自然数public class Program
{
public static void Main()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddUserSecrets<Program>()
.AddEnvironmentVariables(); ;
IConfigurationRoot configuration = builder.Build();
var settings = new ApplicationOptions();
configuration.GetSection("AppSettings").Bind(settings);
var services = new ServiceCollection();
// This is the client I'll use to log in and get a session token
services.AddHttpClient("Authentication", c =>
{
c.BaseAddress = new Uri(settings.AuthenticationApi);
c.DefaultRequestHeaders.Accept.Clear();
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
c.DefaultRequestHeaders.Add("X-Application", settings.AppKey);
c.DefaultRequestHeaders.Add("User-Agent", "My API Client v0.0.1");
}).ConfigurePrimaryHttpMessageHandler(() =>
{
return GetMessageHandlerWithSecurityCertificate(settings);
});
// and this is the next of several clients where I'll need to send the session token with my requests
services.AddHttpClient("AnotherApi", c =>
{
c.BaseAddress = new Uri(settings.AnotherApi);
c.DefaultRequestHeaders.Accept.Clear();
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
c.DefaultRequestHeaders.Add("X-Application", settings.AppKey);
c.DefaultRequestHeaders.Add("User-Agent", "My API Client v0.0.1");
//c.DefaultRequestHeaders.Add("ssoid", sessionToken);
// What should I do here? I want to add a sessionToken string but I can only get the token's value by using the other HttpClient (above) to log in!
});
// Removed one more HttpClient for brevity
}
private static HttpMessageHandler GetMessageHandlerWithSecurityCertificate(ApplicationOptions settings)
{
var handler = new HttpClientHandler();
handler.ClientCertificates.Add(GetSecurityCertificate(settings.SslCertificateFilename, settings.SslCertificatePassword));
return handler;
}
private static X509Certificate2 GetSecurityCertificate(string certFilename, string certPassword)
{
return new X509Certificate2(certFilename, certPassword);
}
}
可描述为不同斐波纳契数的总和。斐波那契位序列描述了哪个斐波那契数用于x
的最终求和。斐波那契位序列中的x
或set bit
选择相应的斐波那契数。示例1
表示00101
+ F2
= F4
+ 1
= 3
。
例如,对于数字4
,我们具有以下有效位序列。在本例中,位序列后面的斐波那契数如下:
39
0,1,1,2,3,5,8,13,21,34
0000010001
k = 2
r = 0
0000010110
k = 3
r = 0
0001100001
k = 3
r = 1
0001100110
k = 4
r = 0
0001111010
k = 5
r = 0
0110100110
k = 5
r = 1
0110111010
k = 6
所以我们有以下参数:
r = 0
代表号码
n
位序列中的1的计数
k
在r
和n
描述的子集中的排名。
如何使用参数r
进行排名?是否存在算法?