URAL 1009 K-based Numbers】的更多相关文章

题目传送门 题意:n位数,k进制,求个数分析:dp[i][j] 表示i位数,当前数字为j的个数:若j==0,不加dp[i-1][0]; 代码1: #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; const int MAXN = 22; const int INF = 0x3f3f3f3f; long long…
Find first K frequency numbers /* * Input: int[] A = {1, 1, 2, 3, 4, 5, 2}; k = 3 * return the highest frequency numbers. * return: [1, 2, 3] or [1, 2, 4] or [1, 2, 5] * */ 找出出现频率前k的数字 SOLUTION 1: 先将数字全放入一个map, key为数字,value为frequency, 对map排序,时间复杂度是Nl…
Given a target number, a non-negative integer k and an integer array A sorted in ascending order, find the k closest numbers to target in A, sorted in ascending order by the difference between the number and target. Otherwise, sorted in ascending ord…
Given an integer array, find the top k largest numbers in it.   Example Given [3,10,1000,-99,4,100] and k = 3. Return [1000, 100, 10]. 解法一: class Solution { public: /* * @param nums: an integer array * @param k: An integer * @return: the top k larges…
Given an integer array, find the top k largest numbers in it. Example Given [3,10,1000,-99,4,100] and k = 3.Return [1000, 100, 10]. 思路:由于需要按从大到小的顺序,因此直接用PriorityQueue即可,用Partition的方法的话还需要排序.直接用PriorityQueue 写的代码量少. class Solution { /* * @param nums a…
题目如下: Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into sets of k consecutive numbersReturn True if its possible otherwise return False. Example 1: Input: nums = [1,2,3,3,4,4,5,6], k = 4 Ou…
http://acm.timus.ru/problem.aspx?space=1&num=1009 题意:将一个n位数转化为合法的K进制数,有多少种情况.合法的K进制数即不含前导0,且任意两个0都不相邻. 思路:每一位的情况都分为:小于K且不等于0的情况或等于0的情况,每一位的选择都有前一位决定.dp[i][0]表示第i位为0的情况,dp[i][1]表示第i位不为0的情况,则 dp[i][0] = dp[i-1][1],dp[i][1] = (dp[i-1][1]+dp[i-1][0])*(k-…
点我看题目 题意 : K进制的N位数,不能有前导零,这N位数不能有连续的两个0在里边,问满足上述条件的数有多少个. 思路 : ch[i]代表着K进制的 i 位数,不含两个连续的0的个数. 当第 i 位为0时,那么第i-1位不为0有(K-1)种放法,(k-1)*f[i-2] 当第 i-1 位为0时,第 i 位有(k-1)种放法,(k-1)*f[i-1] #include <stdio.h> int main() { ]; int m,n; while(~scanf("%d %d&quo…
题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; ; int n, k; ][][]; // dp[i][j][k]表示i进制下j位数以k结尾的个数(k=0表示以0结尾:k=1表示不以0结尾) int main() { ; i<=; i++ ) { dp[i][][] = ; dp[i][][] = i-; ; j<…
1523. K-inversions Time limit: 1.0 secondMemory limit: 64 MB Consider a permutation a1, a2, …, an (all ai are different integers in range from 1 to n). Let us call k-inversion a sequence of numbers i1, i2, …, ik such that 1 ≤ i1 < i2 < … < ik ≤ n…