摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 1 #include<stdio.h> 2 struct node{ 3 int x,y; 4 }; 5 int main() 6 { 7 struct node a[1001]; 8 int record[1001],flag,sum,i,j,t1,n,T,t2; 9 //freopen("1.txt","r",stdin);10 scanf("%d",&T);11 while(T--)12 {13 scanf
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2037 1 #include<stdio.h> 2 struct node{ 3 int x,y; 4 }; 5 int main() 6 { 7 struct node a[101]; 8 int i,j,n,sum,q,y,w,t; 9 //freopen("1.txt","r",stdin);10 while(scanf("%d",&n)!=EOF&&n)11 {12 for(i=0;i<n;
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1231 1 #include<stdio.h> 2 int main() 3 { 4 int n,i,j,k1,k2,sum,sumx; 5 int a[10000],leap1,leap2; 6 while(scanf("%d",&n)!=EOF&&n) 7 { 8 for(i=0;i<n;i++) 9 scanf("%d",&a[i]);10 leap1=0;11 leap2=1;12 ...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2159 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 //up 升级所需经验值 6 //n 怪兽种类 7 // volumn1 最大忍耐度 8 //volumn2 最多打怪数 9 //value[i] 打怪经验值 10 //cost1[i] 忍耐度的消耗11 //cost2[i] 打怪数的消耗12 //record[][] 二维背包13 int recor...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2191思路是将数量为n的物品按1 2 4 8 16.....分割成多个物品,然后按0/1背包的思路做,1 2 4 8...分别代替二进制中的一个位,可以通过加得到任何数,如13分为 1 2 4 6 1 #include<stdio.h> 2 #include<string.h> 3 #define MAX 510 4 #define max(a,b) (a>b?a:b) 5 int main() 6 { 7 int value[MAX],weight[MAX],reco
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114注:1.01背包使用的是逆序,完全背包使用的顺序。2.此题不是求最大,而是在满足背包全满的条件下,使之价值最小,也就是求最低下限。 1 #include<stdio.h> 2 #include<string.h> 3 #define MAX 501 4 #define INF 0x3f3f3f3f 5 #define min(a,b) (a>b?b:a) 6 int main() 7 { 8 long int weight[MAX],value[MAX],reco
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1864 1 #include<stdio.h> 2 int main() 3 { 4 double price,sum,a,value[31],record[31]; 5 int c,t,i,j,flag,n,sa,sb,sc; 6 char str; 7 //freopen("1.txt","r",stdin); 8 while(scanf("%lf%d",&price,&c)!=EOF&&c)
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 1 #include<stdio.h> 2 int main() 3 { 4 int t; 5 double value[105],P,gailv; 6 int volumn[105]; 7 double record[105*100]; 8 int V,i,n,j,price; 9 //freopen("1.txt","r",stdin);10 scanf("%d",&t);11 while(t--)12 {1
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=26021.此题的约束条件volume是整形的。用三个数组,volume,value和record,分别记录体积,价值,和判断后的价值,record的下标代表空间,其值代表判断i个物品后各个空间的总价值。2.对于每一个物品,考虑每一种空间的情况,如第一个物品时,空间为10时,有两种情况,一是不取,二是取,然后将其值和剩下空间能得到的最大价值相加,选取两者中价值最大的。如如第一次判断时,物品1的volume是5,value是1,当V=10时,初始化时,record都置零,那么此时,record[10]=
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=20841.此题暴力解决会超时,需用动态规划,如果用递归的话,也回超时,所以需要在递归上改进一下。2.用两个数组,一个叫奇数组,标号为a[1][],一个叫偶数组,为a[0][];第一次是奇数组存储读入的数,偶数组存储操作结果,第二次是偶数组存取读入数,奇数组存储操作结果,这样循环。 1 #include<Stdio.h> 2 #include<string.h> 3 #define MAX 101 4 #define max(a,b) (a>b?a:b) 5 int ma
阅读全文