Gym 100418J Lucky tickets(数位dp)】的更多相关文章

Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86686#problem/J Description Everyone knows that in less than a month the Ice Hockey World Championship will start in Minsk. But few of the…
题意:给定一个n.求区间[1, n]之间的全部的a的个数.a满足: a能整除  把a表示自身二进制以后1的个数 思路:题意非常绕.... 数位dp,对于全部可能的1的个数我们都dfs一次 对于某一个可能的1的个数p来说.状态dp(len, i, j, k)里的每一位分别表示当前位,当前确定位的值模除p,已经有了多少个1.是否已经小于给定的n. 注意的是这题范围非常大,要用unsigned long long 来定义n #include<cstdio> #include<cstring&g…
http://codeforces.com/gym/100623/attachments 题意:问1到n里面有多少个数满足:本身被其各个数位加起来的和整除.例如120 % 3 == 0,111 % 3 == 0,都算. 思路:老是写不出数位DP... 因为n最大为12位,所以取模的数最大可以是9*12 == 108,因此枚举这个模. dfs记录的状态有:pos, sum, mod, remain, flag. pos代表枚举到第几位, sum代表数位之和, mod代表当前枚举的模, remain…
题目链接:http://poj.org/problem?id=2346 思路分析:使用动态规划解法:设函数 d( n, x )代表长度为n且满足左边n/2位的和减去右边n/2位的和为x的数的数目. 将一个长度为n的数看做n个数字 A1, A2....An ( 0 <= Ai <= 9  ),将字符分为两个集合{ A1, A2....An/2 } 与 { An/2+1.....An }; 问题转换为求集合中元素和相等的数目.先从每个集合中选出一个元素,求它们差为a的可能数目,即d( 2, a )…
题意:求[a,b]区间内的数字中正序对的个数. 具体思路参考: https://blog.csdn.net/weixin_43135318/article/details/88061396 https://www.cnblogs.com/asdfsag/p/11278519.html 在此基础上维护一下每个状态中大于每个数字的数字出现的次数即可. #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ll bi…
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description Start with an integer, N0, which is greater than 0. Let N1 be the number of ones in the binary representation of N0. So, if N0 = 27, N1 = 4. For all i > 0, let Ni be the number…
Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3298 Accepted: 2174 Description The public transport administration of Ekaterinburg is anxious about the fact that passengers don't like to pay for passage doing their best to a…
题目传送门 /* 题意:转换就是求n位数字,总和为s/2的方案数 DP+高精度:状态转移方程:dp[cur^1][k+j] = dp[cur^1][k+j] + dp[cur][k]; 高精度直接拿JayYe的:) 异或运算的规则: 0⊕0=0,0⊕1=1 1⊕0=1,1⊕1=0 口诀:相同取0,相异取1 */ #include <cstdio> #include <cstring> #include <string> #include <iostream>…
题目链接 题意:判断小于n的数字中,数位从高到低成上升再下降的趋势的数字的个数 分析:简单的数位DP,保存前一位的数字,注意临界点的处理,都是套路. #include <bits/stdc++.h> typedef long long ll; const int N = 70 + 5; char str[N]; ll dp[N][10][2]; int len; ll DFS(int pos, int pre, int up, int limit) { if (pos == len) { re…
Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86821#problem/B Description Little John studies numeral systems. After learning all about fixed-base systems, he became inte…