摘要:动态规划题,所有的humble number表示为 n = (2^i)*(3^j)*(5^k)*(7^l)。需要注意的是,i,j,k,l也只能是humble number,因此只能从已产生的humble number数组中选取。 1 #include 2 long long int a[5843]; 3 long long int t1,t2,t3,t4; 4 5 long long int minimum(int a1, int a2, int a3, int a4) 6 { 7 long long int ret = a1; 8 if (a2 <= ret) { 9 ...
阅读全文
摘要:贪心法,每次都尽可能的多买性价比高的物品。 1 #include 2 #include 3 4 using namespace std; 5 struct Room { 6 int food; 7 int javabean; 8 }; 9 10 bool cmp(struct Room r1, struct Room r2)11 {12 double d1 = (double)(r1.javabean)/(double)(r1.food);13 double d2 = (double)(r2.javabean)/(double)(r2.food);14 retur...
阅读全文
摘要:动态规划题,转移方程:C[i]=max{C[i-1]+A[i], A[i]} i=1,2,...,n C[0] = 0OPT(A) = max{C[i]}, i=1,2,...,n。最大的整数可以通过先将-1转成无符号整数,然后逻辑右移得到。需要注意几组特殊的数据:0 0 -1 0; -1 -2 -3; 1 2 3 -7 1 2 3。 1 #include 2 3 #define MAX_INT ((unsigned long)(-1)>> 1) 4 #define MIN_INT (MAX_INT+1) 5 6 int a[100000]; //store the number
阅读全文
摘要:实现大整数运算,完成bigInteger类封装。 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 const int N = 1000; 8 class bigInteger 9 {10 friend ostream& operator=0; --i)29 if (i!= A.size-1)30 out =0; --i) {43 t += (str[i]-'0')*c;44 j++;45 c *...
阅读全文