[2016-03-28] [HDU] [1074] [Doing Homework]

Source: Internet
Author: User

    • Time: 2016-03-28-18:46:36
    • Title Number: [2016-03-28][hdu][1074][doing homework]
    • The main topic: given n the time period of the operation of the Department and the completion of times, each subject each more than one day to deduct a copy, the minimum deduction points
    • Analysis: N only 15, binary enumeration, state compression, enumerate the status of each account completion, update the next state, find the minimum value
  
 
  1. #include <cstring>
  2. #include <cstdio>
  3. using namespace std;
  4. const int maxstu = 1 << 16;
  5. struct Cource{
  6. char name[20];
  7. int d,c;
  8. }a[16];
  9. struct mstatus{
  10. int pre,cost,reduced,id;
  11. Mstatus(inta= 0,intb= 0,intC= 0,intD= 0): Cost(a),reduced(b),Pre(C),ID(D){};
  12. }dp[maxstu];
  13. int vis[maxstu];
  14. void print(int cur){
  15. if(dp[cur].pre == 0){
  16. printf("%s\n",a[ dp[cur].id ].name);
  17. return ;
  18. }
  19. print(dp[cur].pre);
  20. printf("%s\n",a[ dp[cur].id ].name);
  21. }
  22. int main(){
  23. int T;
  24. scanf("%d",&T);
  25. while(T--){
  26. int n;
  27. scanf("%d",&n);
  28. for(int i = 0;i < n;++i){
  29. scanf("%s%d%d",a[i].name,&a[i].d,&a[i].c);
  30. }
  31. memset(vis,0,sizeof(vis));
  32. dp[0] = mstatus(0,0,0,0);
  33. for ( int i = 0 ; i < ( 1 << n ) - 1 ;++ i
  34. for(int j = 0;j < n;++j){
  35. int cur = 1 << j;
  36. if((cur & i) == 0){
  37. int curcost = dp[i].cost + a[j].c;
  38. int curreduced = DP [ i . reduced + ( curcost <= a [ j . d 0 : curcost - a [ j . d
  39. int nxtstatus = cur | i;
  40. if(vis[nxtstatus]){
  41. if(curreduced < dp[nxtstatus].reduced){
  42. dp[nxtstatus] = mstatus(curcost,curreduced,i,j);
  43. }
  44. }else {
  45. vis[nxtstatus] = 1;
  46. dp[nxtstatus] = mstatus(curcost,curreduced,i,j);
  47. }
  48. }
  49. }
  50. }
  51. int ans = dp[(1 << n) - 1].reduced;
  52. printf("%d\n",ans);
  53. print((1 << n) - 1);
  54. }
  55. return 0;
  56. }


From for notes (Wiz)

[2016-03-28] [HDU] [1074] [Doing Homework]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.