poj 2459 Sumsets】的更多相关文章

Sumsets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11612   Accepted: 3189 Description Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S. Input Several S, each cons…
Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 11892   Accepted: 4782 Description Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer…
http://poj.org/problem?id=2229 题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数.问你不同方案数之和是多少? n很大,所以输出后9位即可. dp[i] 表示组成i的不同方案数,那么 dp[1]=1;dp[2]=2; if(i%2) dp[i]=dp[i-1] ;  i如果是奇数,那么只能在i-1的每个方案数前面加上1得到i,所以方案数相等. else dp[i]=dp[i-1]+dp[i/2] ;  i如果是偶数,一种可能是i有两个1,在i-1的每个方案…
Sumsets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10593   Accepted: 2890 Description Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S. Input Several S, each cons…
                                                                                                 Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 16876   Accepted: 6678 Description Farmer John commanded his cows to search for dif…
Sumsets Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 400000/200000K (Java/Other) Total Submission(s) : 4   Accepted Submission(s) : 3 Problem Description Farmer John commanded his cows to search for different sets of numbers that sum to a g…
Sumsets Description Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer power of 2. Here are the possible sets of numbers that sum to 7: 1) 1+1+1+1+1+1+1 2)…
Sumsets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11946   Accepted: 3299 Description Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S. Input Several S, each cons…
题目大意:找到几何中的4个数字使他们能够组成 a+b+c=d , 得到最大的d值 我们很容易想到a+b = d-c 那么将所有a+b的值存入hash表中,然后查找能否在表中找到这样的d-c的值即可 因为4个数字都不能相同,那么我们同时要在hash表中记录相加两个数的下标,然后查找的时候还要进行下标判断 这里用二分查找也可以,但是能用hash还是hash快地多了 这里第一次写到对负数进行hash,还是傻傻地 val%MOD , 但是负数得到的模值为负,作为hash的下标会RE,所以RE了一发,还是…
题意:给定一个整数N (1<= N <= 1000000),求出以 N为和 的式子有多少个,式子中的加数只能有2的幂次方组成 如5 : 1+1+1+1+1.1+1+1+2.1+2+2.1+4,共有5个 思路:当N为奇数时,N的式子中都必有1,故知只需在N-1的式子中都+1就可以,即d[N] = d[N-1] 当N为偶数时,N的式子可以分为,有1 或者 没1:有1的式子,必有2个1,那么可以由N-2的式子加上两个1: 没有1的式子,把式子中的加数都除以2,故可以由N/2的式子求得. AC代码:…