BZOJ2612 : [Poi2003]Sums】的更多相关文章

设d[i]表示能拼出的x中满足x%a[0]=i的最小的x,其中d[0]=0. 若d[x%a[0]]<=x,则一定可以拼出x,否则一定不可以. 建出带权有向图,点的标号从0到a[0]-1,i号点向(i+a[j])%a[0]号点连边,边权为a[j]. 一遍Dijkstra求出单源最短路即可完成预处理. 时间复杂度$O(na_0\log a_0)$. #include<cstdio> #include<vector> #include<algorithm> #inclu…
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2612 [题目大意] 给定a数组,问num能否被表示为a[1]*x[1]+a[2]*x[2]+……+a[n]*x[n],x为非负整数 [题解] 设a1为最小数字, 若方程a[1]*x[1]+a[2]*x[2]+……+a[n]*x[n]=k存在非负整数解,那么k+a1也必然有解. 建立a1个点的图,点编号为0到a1-1,i向(i+aj)%a1连边,边权为aj,求src为0的最短路, 如果…
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem 10983 18765 Y 1036 [ZJOI2008]树的统计Count 5293 13132 Y 1588 [HNOI2002]营业额统计 5056 13607 1001 [BeiJing2006]狼抓兔子 4526 18386 Y 2002 [Hnoi2010]Bounce 弹飞绵羊 43…
You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define a pair (u,v) which consists of one element from the first array and one element from the second array. Find the k pairs (u1,v1),(u2,v2) ...(uk,vk) wit…
UVA - 11997 K Smallest Sums Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status] Description   Problem K K Smallest Sums You're given k arrays, each array has k integers. There are kk ways to pick…
Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6350   Accepted: 3673 Description FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum ad…
本题的特点在于两个list nums1和nums2都是已经排序好的.本题如果把所有的(i, j)组合都排序出来,再取其中最小的K个.其实靠后的很多组合根本用不到,所以效率较低,会导致算法超时.为了简便,把nums1和nums2里面的元素写成A1,A2,...,A5, B1,...,B5. 维护一个最小堆.并逐渐往里面push and pop元素. 注意以下几点:1. 如果(Ai, Bj)大于堆顶的元素,那么没有比较把(Ai, Bj)和它之后的元素Push进堆.2. 为了便于管理,解法里其实只维护…
题目 Source http://www.spoj.com/problems/TSUM/ Description You're given a sequence s of N distinct integers.Consider all the possible sums of three integers from the sequence at three different indicies.For each obtainable sum output the number of diff…
2065. Different Sums Time limit: 1.0 secondMemory limit: 64 MB Alex is a very serious mathematician and he likes to solve serious problems. For example, this problem. You are to construct an array of n integers in which the amount of different intege…
题目链接: A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wan…