【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

会发现。
进行一次操作过后。
得到的数字肯定是可以写一个数位dp的。

即统计二进制数字y,满足y中1的个数为x然后y<=n

(一旦已经小于n了,则直接用组合数算方案就可以了

k=0和k=1要特殊处理一下

具体看代码

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std; const int N = 1e3;
const ll MOD = 1e9+7; int k,a[N+10],n;
ll ans = 0,C[N+10][N+10];
string s;
vector<int> v; int GetNext(int x){
int y = 0;
while (x){
y+=(x&1);
x>>=1;
}
return y;
} void dfs(int pos,int rest,bool xiao){
if (n-pos+1<rest) return;
if (rest==0){
ans = (ans+1)%MOD;
return;
}
if (pos>n) return; if (xiao){
ans = (ans + C[n-pos+1][rest])%MOD;
return;
}
if (a[pos]==1){
dfs(pos+1,rest-1,xiao);
dfs(pos+1,rest,true);
}else{
if (xiao) dfs(pos+1,rest-1,xiao);
dfs(pos+1,rest,xiao);
}
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0); for (int i = 0;i <=N;i++)
C[i][i] = C[i][0] = 1;
for (int i = 1;i <= N;i++)
for (int j = 1;j <= i-1;j++)
C[i][j] = (C[i-1][j]+C[i-1][j-1])%MOD; cin >> s;
cin >>k; for (int i = 0;i<(int) s.size();i++)
a[i+1] = s[i]-'0';
n = (int)s.size(); if (k==0){
cout <<1<<endl;
return 0;
} //what if n==1 k==0
for (int i = 1;i <=N;i++){
int x = i;
int step = 0;
while (x!=1){
step++;
x=GetNext(x);
}
if (step==(k-1)) {
v.push_back(i);
}
} for (int i = 0;i<(int)v.size();i++){
dfs(1,v[i],false);
}
if (k==1) {
ans = (ans-1+MOD)%MOD;
}
cout << ans << endl;
return 0;
}

【Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined) C】 Travelling Salesman and Special Numbers的更多相关文章

  1. Codeforces 914C Travelling Salesman and Special Numbers:数位dp

    题目链接:http://codeforces.com/problemset/problem/914/C 题意: 对数字x进行一次操作,可以将数字x变为x在二进制下1的个数. 显然,一个正整数在进行了若 ...

  2. Travelling Salesman and Special Numbers CodeForces - 914C (数位dp)

    大意: 对于一个数$x$, 每次操作可将$x$变为$x$二进制中1的个数 定义经过k次操作变为1的数为好数, 求$[1,n]$中有多少个好数 注意到n二进制位最大1000位, 经过一次操作后一定变为1 ...

  3. Codeforces 914 C. Travelling Salesman and Special Numbers (数位DP)

    题目链接:Travelling Salesman and Special Numbers 题意: 给出一个二进制数n,每次操作可以将这个数变为其二进制数位上所有1的和(3->2 ; 7-> ...

  4. Codeforces 374 C. Travelling Salesman and Special Numbers (dfs、记忆化搜索)

    题目链接:Travelling Salesman and Special Numbers 题意: 给了一个n×m的图,图里面有'N','I','M','A'四种字符.问图中能构成NIMA这种序列最大个 ...

  5. Codeforces 914 C Travelling Salesman and Special Numbers

    Discription The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pas ...

  6. Codeforces 914C Travelling Salesman and Special Numbers (数位DP)

    题意:题目中定义了一种运算,把数字x变成数字x的二进制位数.问小于n的恰好k次运算可以变成1的数的个数(题目中的n是二进制数,n最大到2^1000) 思路:容易发现,无论多么大的数,只要进行了一次运算 ...

  7. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  8. Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块

    Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ​ ...

  9. Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题

    Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] ​ 总共两次询 ...

随机推荐

  1. [LNOI2014]LCA 树链剖分 离线 前缀和 思维题

    题目描述:给出一个n个节点的有根树(编号为0到n-1,根节点为0).一个点的深度定义为这个节点到根的距离+1. 设dep[i]表示点i的深度,LCA(i,j)表示i与j的最近公共祖先. 有q次询问,每 ...

  2. d3的一些总结

    核心操作:https://blog.csdn.net/kriszhang/article/details/70174410 Update.Enter.Exit 简练详细说明:http://www.cn ...

  3. AtCoderBeginner091-C 2D Plane 2N Points 模拟问题

    题目链接:https://abc091.contest.atcoder.jp/tasks/arc092_a 题意 On a two-dimensional plane, there are N red ...

  4. 前端之CSS选择器

    基本选择器 元素选择器 p {color: "red";} ID选择器 #i1 { background-color: red; } 类选择器 .c1 { font-size: 1 ...

  5. Xwiki平台Windows搭建(Tomcat7 + XWiki6.2 + MySQL5.5)

    背景介绍 国内xwiki安装使用资料较少,根据自己使用xwiki经验,总结出来,供参考,同时希望感兴趣的朋友能够一起讨论,XWiki是一个强大的Java开源的Wiki引擎. 它支持一些受欢迎的特性如: ...

  6. POJ——T 1986 Distance Queries

    http://poj.org/problem?id=1986 Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 14383   ...

  7. ArcGIS api for javascript—测量,测距问题

    首先量测 var map, toolbar, geometryService ; function init() { map=new esri.Map("map",{ extent ...

  8. 解析XML文件之使用DOM解析器

    在前面的文章中.介绍了使用SAX解析器对XML文件进行解析.SAX解析器的长处就是占用内存小.这篇文章主要介绍使用DOM解析器对XML文件进行解析. DOM解析器的长处可能是理解起来比較的直观,当然, ...

  9. 分享:FIFO 同步、异步以及Verilog代码实现

    FIFO 很重要,之前参加的各类电子公司的逻辑设计的笔试几乎都会考到. FIFO是英文First In First Out 的缩写,是一种先进先出的数据缓存器,他与普通存储器的区别是没有外部读写地址线 ...

  10. Magento--修改已存在的订单的运费

    遇到一种情况,需要在下单后再由管理员添加订单运费,然后顾客再付款.那么问题来了,如何给订单添加运费呢?下面是一段代码,可以实现该功能: $orderId = 'your order id';$orde ...