URAL - 1057 Amount of Degrees--数位dp
来源:互联网 发布:图书数据哪里最多 编辑:程序博客网 时间:2024/04/29 18:00
原题链接:http://vjudge.net/problem/URAL-1057
题意:[ x , y ]里一共有多少个数可以由k个b整数幂组成。
分析:http://wenku.baidu.com/link?url=q4atTAoZVGlV6sfo0fhED06ogbktY38_TZkGWLkuOpTRiqyI-eDyarkTeL10fv2GdUe53DMIloZ_sD0gZF6xK1ljbcJH1NlLgdyh4aVcGXi
#define _CRT_SECURE_NO_DEPRECATE#include<iostream>#include<vector>#include<cstring>#include<queue>#include<stack>#include<algorithm>#include<cmath>#include<string>#include<stdio.h>#define INF 99999999#define eps 0.0001using namespace std;int dp[35][35];//dp[i][j]表示深度为i有j个1的种类,根深度为0int x, y, k, b;int cnt[35];void init(){for (int i = 0; i <= 31; i++){dp[i][0] = 1;for (int j = 1; j <= i; j++)dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];}}int solve(int n){int len = 0;int ans = 0;int ik = k;int ib = b;while (n){cnt[len++] = n%ib;n /= ib;}for (int i = len - 1; i >= 0; i--){if (cnt[i] == 1){ans += dp[i][ik];//以0开头,找到k个1;然后k--,固定开头为1,继续做ik--;}else if (cnt[i] > 1){ans += dp[i + 1][ik];break;}if (ik < 0)//注意是小于0return ans;}if (ik == 0)//n本身满足ans++;return ans;}int main() {init();while (~scanf("%d%d%d%d", &x, &y, &k, &b)){printf("%d\n", solve(y) - solve(x - 1));}return 0;}
1 0
- [数位dp] ural 1057 Amount of Degrees
- ural 1057 Amount of Degrees(数位DP)
- ural 1057 Amount of degrees 【数位dp】
- 【URAL】1057 Amount of Degrees 数位DP
- URAL 1057 Amount of Degrees (数位dp)
- 数位DP-URAL-1057-Amount of Degrees
- 【URAL 1057】 Amount of Degrees 【数位DP】
- 【数位DP】URAL 1057 Amount of Degrees
- URAL 1057 Amount of Degrees(数位dp)
- URAL 1057 Amount of Degrees 数位DP *
- URAL - 1057 Amount of Degrees--数位dp
- URAL 1057 Amount of Degrees 数位dp
- Ural 1057 Amount of Degrees【数位Dp】
- ural 1057 Amount of Degrees(数位dp)
- ural 1057 Amount of degrees 数位DP (入门)
- URAL 1057 - Amount of Degrees (入门数位DP)
- URAL 1057 Amount of Degrees(数位DP)
- URAL 1057 Amount of Degrees (数位DP)
- 经典问题之最少交换次数
- Java Reintroduction for Concepts
- Leetcode-160. Intersection of Two Linked Lists
- 数学,容斥原理(拉拉队,uva 11806)
- RabbitMq与Kafka集群设计比较
- URAL - 1057 Amount of Degrees--数位dp
- Linux下MySQL定时备份
- LeetCode 374. Guess Number Higher or Lower
- 51nod 1012 最小公倍数LCM
- ElasticSearch以及相关插件在window下的安装
- 【JDK源码阅读2-util】Collection-List
- 51nod 1013 3的幂的和
- 应用GregorianCalendar类的日历程序
- 计算二元函数