USACO section 3.3 Shopping Offers(DP或最短路)

USACO Training 综述 USACO http://www.nocow.cn/index.php/USACO_Training (USACO 97道题)   USA Computing Olympiad 是美国高校的信息学测评网站,也是美国中学生的官方竞赛网站。   美国著名在线题库,专门为信息学竞赛选手准备。   全英文界面,但有非官方的中文翻译。推荐直接阅读英语原文,既准确可靠又可提高英语水平。   网站的Traini... 阅读详情
Shopping Offers
IOI'95

In a certain shop, each kind of product has an integer price. For example, the price of a flower is 2 zorkmids (z) and the price of a vase is 5z. In order to attract more customers, the shop introduces some special offers.

A special offer consists of one or more product items together for a reduced price, also an integer. Examples:

  • three flowers for 5z instead of 6z, or
  • two vases together with one flower for 10z instead of 12z.

Write a program that calculates the price a customer has to pay for a purchase, making optimal use of the special offers to make the price as low as possible. You are not allowed to add items, even if that would lower the price.

For the prices and offers given above, the (lowest) price for three flowers and two vases is 14z: two vases and one flower for the reduced price of 10z and two flowers for the regular price of 4z.

PROGRAM NAME: shopping

INPUT FORMAT

The input file has a set of offers followed by a purchase.

Line 1:s, the number of special offers, (0 <= s <= 99).
Line 2..s+1:Each line describes an offer using several integers. The first integer is n (1 <= n <= 5), the number of products that are offered. The subsequent n pairs of integers c and k indicate that k items (1 <= k <= 5) with product code c (1 <= c <= 999) are part of the offer. The last number p on the line stands for the reduced price (1 <= p <= 9999). The reduced price of an offer is less than the sum of the regular prices.
Line s+2:The first line contains the number b (0 <= b <= 5) of different kinds of products to be purchased.
Line s+3..s+b+2:Each of the subsequent b lines contains three values: c, k, and p. The value c is the (unique) product code (1 <= c <= 999). The value k indicates how many items of this product are to be purchased (1 <= k <= 5). The value p is the regular price per item (1 <= p <= 999). At most 5*5=25 items can be in the basket.

SAMPLE INPUT (file shopping.in)

2
1 7 3 5
2 7 1 8 2 10
2
7 3 2
8 2 5

OUTPUT FORMAT

A single line with one integer: the lowest possible price to be paid for the purchases.

SAMPLE OUTPUT (file shopping.out)

14

思路: 因为最多只有5种商品,所以可以猥琐的五维Dp直接过,效率还不错11ms.

           状态方程:ans[][][][][]=min(ans[][][][][[],ans[i-c1][j-c2][k-c3][l-c4][m-c5]);其中ci,c2,c3,c4,c5自然是优惠方案中,各商品的需求数,

                            不用说得先判断能构成优惠方案。

注意点:商品名得处理下下,我是按照先来后到给它排号

 

/*
ID:nealgav1
LANG:C++
PROG:shopping
*/
#include<fstream>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
ifstream cin("shopping.in");
ofstream cout("shopping.out");
const int mm=7;
const int mn=111;
///五维数组表示最多五种不同商品
int ans[mm][mm][mm][mm][mm];
///借助MAP给商品名标号排序
map<int,int>mp;
int m,n;
class node
{
  public:
  int name[mm];///商品名
  int num[mm];///商品个数
  int one_cost[mm];///单价
  int cost;///优惠价格
  node()
  {
    cost=0;memset(name,0,sizeof(name));
    memset(num,0,sizeof(num));
    memset(one_cost,0,sizeof(one_cost));
  }
};
node cheap[mn],need;///优惠方案与需求数
int main()
{
  cin>>m;
  int type_num,pos=1;
  for(int i=0;i<m;i++)///m种优惠方案
  {
    cin>>type_num;
   for(int j=0;j<type_num;j++)
   {
     int _name,_num;
     cin>>_name>>_num;
     if(mp[_name])///已经给该商品排过号
     {//cheap[i].name[mp[_name]-1]=_name;
      cheap[i].num[mp[_name]-1]=_num;
     }
     else {mp[_name]=pos++;///未给商品排号,则先排号
    //  cheap[i].name[mp[_name]-1]=_name;
      cheap[i].num[mp[_name]-1]=_num;
     }
   }
       cin>>cheap[i].cost;///优惠价
  }
  cin>>n;
  for(int j=0;j<n;j++)///需求
  {
    int _name;
    int _pos;
    cin>>_name;
    if(mp[_name])
    {_pos=mp[_name]-1;
     // need.name[_pos]=_name;
      cin>>need.num[_pos]>>need.one_cost[_pos];
    }else
    {mp[_name]=pos++;
     _pos=mp[_name]-1;
     //need.name[_pos]=_name;
     cin>>need.num[_pos]>>need.one_cost[_pos];///单价
    }
  }
  int i[7];
  ///最多五种商品,五维DP
  for(i[0]=0;i[0]<=need.num[0];i[0]++)
  for(i[1]=0;i[1]<=need.num[1];i[1]++)
  for(i[2]=0;i[2]<=need.num[2];i[2]++)
  for(i[3]=0;i[3]<=need.num[3];i[3]++)
  for(i[4]=0;i[4]<=need.num[4];i[4]++)
  { ans[i[0]][i[1]][i[2]][i[3]][i[4]]=0;
    for(int ii=0;ii<5;ii++)///商品全部单买
    ans[i[0]][i[1]][i[2]][i[3]][i[4]]+=i[ii]*need.one_cost[ii];
    for(int j=0;j<m;j++)
    { bool flag=1;
     for(int k=0;k<5;k++)///判断是否符合第J种优惠
     if(i[k]-cheap[j].num[k]<0)
     flag=0;
     if(flag)///符合,则取优惠的的最优
     ans[i[0]][i[1]][i[2]][i[3]][i[4]]=min(ans[i[0]][i[1]][i[2]][i[3]][i[4]],
     ans[i[0]-cheap[j].num[0]][i[1]-cheap[j].num[1]][i[2]-cheap[j].num[2]]
     [i[3]-cheap[j].num[3]][i[4]-cheap[j].num[4]]+cheap[j].cost);
    }
  }
  cout<<ans[need.num[0]][need.num[1]][need.num[2]][need.num[3]][need.num[4]]<<"\n";
}


 

Shopping Offers
Hal Burch

This is a shortest path problem. The goal is to find the shortest path from an empty basket to a basket containing the requested objects. Thus, Dijkstra's algorithm can be used.

The nodes in the graph correspond to baskets and the edges correspond to offers (purchasing a single item can be considered a degenerate offer). The length of an edge is the cost of the offer. For each item type, there can be between 0 and 5 inclusive objects of that type in the basket, for a total of 65 = 7,776 possible baskets.

#include <stdio.h>
#include <string.h>

/* maximum number of offers */
/* 100 offers + 5 degenerate offers */
#define MAXO 105

typedef struct OFFER_T
 {
  int nitem; /* number of items in the offer */
  int itemid[5]; /* item's id */
  int itemamt[5]; /* item's amount */
  int cost; /* the cost of this offer */
 } offer_t;

offer_t offers[MAXO];
int noffer;

/* the cost of each basket type */
int cost[7776];

/* the item statistics */
int itemid[5]; /* the id */
int itemcst[5]; /* the cost of buying just 1 */
int nitem;

/* heap used by Dijkstra's algorithm */
int heap[7776];
int hsize;
int hloc[7776]; /* location of baskets within the heap */

/* debugging routine */
void check_heap(void)
 { /* ensure heap order is maintained */
  int lv;
  return;

  for (lv = 1; lv < hsize; lv++)
   {
    if (cost[heap[lv]] < cost[heap[(lv-1)/2]])
     {
      fprintf (stderr, "HEAP ERROR!\n");
      return;
     }
   }
 }

/* delete the minimum element in the heap */
void delete_min(void)
 {
  int loc, val;
  int p, t;

  /* take last item from the heap */
  loc = heap[--hsize];
  val = cost[loc];

  /* p is the current position of item (loc,val) in the heap */
  /* the item isn't actually there, but that's where we're
     considering putting it */
  p = 0; 

  while (2*p+1 < hsize)
   { /* while one child is less than the last item,
        move the lesser child up */
    t = 2*p+1;
    /* pick lesser child */
    if (t+1 < hsize && cost[heap[t+1]] < cost[heap[t]]) t++;

    if (cost[heap[t]] < val)
     { /* if child is less than last item, move it up */
      heap[p] = heap[t];
      hloc[heap[p]] = p;
      p = t;
     } else break;
   }

  /* put the last item back into the heap */
  heap[p] = loc;
  hloc[loc] = p;
  check_heap();
 }

/* we decreased the value corresponding to basket loc */
/* alter heap to maintain heap order */
void update(int loc)
 {
  int val;
  int p, t;

  val = cost[loc];
  p = hloc[loc];

  while (p > 0) /* while it's not at the root */
   {
    t = (p-1)/2; /* t = parent of node */
    if (cost[heap[t]] > val)
     { /* parent is higher cost than us, swap */
      heap[p] = heap[t];
      hloc[heap[p]] = p;
      p = t;
     } else break;
   }

  /* put basket back into heap */
  heap[p] = loc;
  hloc[loc] = p;
  check_heap();
 }

/* add this element into the heap */
void add_heap(int loc)
 {
  if (hloc[loc] == -1)
   { /* if it's not in the heap */

    /* add it to the end (same as provisionally setting it's value
       to infinity) */
    heap[hsize++] = loc;
    hloc[loc] = hsize-1;
   }

  /* set to correct value */
  update(loc);
 }

/* given an id, calculate the index of it */
int find_item(int id)
 {
  if (itemid[0] == id) return 0;
  if (itemid[1] == id) return 1;
  if (itemid[2] == id) return 2;
  if (itemid[3] == id) return 3;
  if (itemid[4] == id) return 4;
  return -1;
 }

/* encoding constants 6^0, 6^1, 6^2, ..., 6^5 */
const int mask[5] = {1, 6, 36, 216, 1296};

void find_cost(void)
 {
  int p;
  int cst;
  int lv, lv2;
  int amt;
  offer_t *o;
  int i;
  int t;

  /* initialize costs to be infinity */
  for (lv = 0; lv < 7776; lv++) cost[lv] = 999*25+1;

  /* offer not in heap yet */
  for (lv = 0; lv < 7776; lv++) hloc[lv] = -1;
  
  /* add empty baset */
  cost[0] = 0;

  add_heap(0);

  while (hsize)
   {
    /* take minimum basket not checked yet */
    p = heap[0];
    cst = cost[p];

    /* delete it from the heap */
    delete_min();

    /* try adding each offer to it */
    for (lv = 0; lv < noffer; lv++)
     {
      o = &offers[lv];
      t = p; /* the index of the new heap */
      for (lv2 = 0; lv2 < o->nitem; lv2++)
       {
        i = o->itemid[lv2];
	/* amt = amt of item lv2 already in basket */
	amt = (t / mask[i]) % 6;

	if (amt + o->itemamt[lv2] <= 5)
	  t += mask[i] * o->itemamt[lv2];
	else
	 { /* if we get more than 5 items in the basket,
	      this is an illegal move */
	  t = 0; /* ensures we will ignore it, since cost[0] = 0 */
	  break;
	 }
       }
      if (cost[t] > cst + o->cost)
       { /* we found a better way to get this basket */

        /* update the cost */
        cost[t] = cst + o->cost;
	add_heap(t); /* add, if necessary, and reheap */
       }
     }
   }
 }

int main(int argc, char **argv)
 {
  FILE *fout, *fin;
  int lv, lv2; /* loop variable */
  int amt[5]; /* goal amounts of each type */
  int a; /* temporary variable */

  if ((fin = fopen("shopping.in", "r")) == NULL)
   {
    perror ("fopen fin");
    exit(1);
   }
  if ((fout = fopen("shopping.out", "w")) == NULL)
   {
    perror ("fopen fout");
    exit(1);
   }

  fscanf (fin, "%d", &noffer);

  /* read offers */
  for (lv = 0; lv < noffer; lv++)
   {
    fscanf (fin, "%d", &offers[lv].nitem);
    for (lv2 = 0; lv2 < offers[lv].nitem; lv2++)
      fscanf (fin, "%d %d", &offers[lv].itemid[lv2], &offers[lv].itemamt[lv2]);
    fscanf (fin, "%d", &offers[lv].cost);
   }

  /* read item's information */
  fscanf (fin, "%d", &nitem);
  for (lv = 0; lv < nitem; lv++)
    fscanf (fin, "%d %d %d", &itemid[lv], &amt[lv], &cost[lv]);

  /* fill in rest of items will illegal data, if necessary */
  for (lv = nitem; lv < 5; lv++) 
   {
    itemid[lv] = -1;
    amt[lv] = 0;
    cost[lv] = 0;
   }

  /* go through offers */
  /* make sure itemid's are of item's in goal basket */
  /* translate itemid's into indexes */
  for (lv = 0; lv < noffer; lv++)
   {
    for (lv2 = 0; lv2 < offers[lv].nitem; lv2++)
     {
      a = find_item(offers[lv].itemid[lv2]);
      if (a == -1)
       { /* offer contains an item which isn't in goal basket */
        
	/* delete offer */

	/* copy last offer over this one */
        memcpy (&offers[lv], &offers[noffer-1], sizeof(offer_t));
	noffer--;

	/* make sure we check this one again */
	lv--;
	break;
       }
      else
        offers[lv].itemid[lv2] = a; /* translate id to index */
     }
   }

  /* add in the degenerate offers of buying single items 8/
  for (lv = 0; lv < nitem; lv++)
   {
    offers[noffer].nitem = 1;
    offers[noffer].cost = cost[lv];
    offers[noffer].itemamt[0] = 1;
    offers[noffer].itemid[0] = lv;
    noffer++;
   }

  /* find the cost for all baskets */
  find_cost();

  /* calculate index of goal basket */
  a = 0;
  for (lv = 0; lv < 5; lv++)
    a += amt[lv] * mask[lv];

  /* output answer */
  fprintf (fout, "%i\n", cost[a]);
  return 0;
 }

Slavi Marinov's Comments

This problem can be solved using dynamic programming. This way is easier to code, and for the test cases it runs for much less than 0.1 seconds.

We keep a five dimensional array sol (it's not that much, because its size is only 5*5*5*5*5*sizeof(special_offer).) Each configuration of the dimensions sol[a][b][c][d][e] corresponds to having a products from the first kind, b products from the second kind, c from the third, etc.

Basically, the DP forumla is the following : sol[a][b][c][d][e]= min (a*price[1]+b*price[2]+c*price[3]+d*price[4]+e*price[5], so[k].price+ sol[a-so[k].prod[1].items] [b-so[k].prod[2].items] [c-so[k].prod[3].items] [d-so[k].prod[4].items] [e-so[k].prod[5].items] ) where k changes from 1 to the number of special offers. Or, in other words, for each field of the array we check which is better :

  • Not to use any special offer
  • To use some special offer

It's very similliar to the knapsack problem. The complexity of this algorithm is O(5*5*5*5*5*100)=O(312,500), which is quite acceptable.

#include <fstream>
#include <cstring>
using namespace std;

ifstream fin ("shopping.in");
ofstream fout("shopping.out");

struct special_offer {
    int n;
    int price;              // the price of that special offer
    struct product {        // for each product we have to keep :
        int id;             // the id of the product
        int items;          // how many items it includes
    } prod[6];
} so[100];                  // here the special offers are kept

int code[1000],             /* Each code is 'hashed' from its real value
                               to a smaller index.  Example :
			       If in the input we have code 111, 934, 55,
			       1, 66 we code them as 1,2,3,4,5. That is
			       kept in code[1000];
                             */

price[6],                   // the price of each product
many[6];                    // how many of each product are to be bought

int s,                      // the number of special offers
    b;                      // the number of different kinds of products to be bought

int sol[6][6][6][6][6];     // here we keep the price of each configuration

void init() {               // reads the input
    fin>>s;
    for (int i=1;i<=s;i++) {
        fin>>so[i].n;
        for (int j=1;j<=so[i].n;j++)
            fin>>so[i].prod[j].id>>so[i].prod[j].items;
        fin>>so[i].price;
    }
    fin>>b;
    for (int i=1;i<=b;i++) {
        int tmp;
        fin>>tmp;
        code[tmp]=i; // here we convert the code to an id from 1..5
        fin>>many[i];
        fin>>price[i];
    }
}

void solve() { // the procedure that solves the problem
    for (int a=0;a<=many[1];a++)
        for (int b=0;b<=many[2];b++)
            for (int c=0;c<=many[3];c++)
                for (int d=0;d<=many[4];d++)
                    for (int e=0;e<=many[5];e++)
                        if ((a!=0)||(b!=0)||(c!=0)||(d!=0)||(e!=0)) {

      int min=a*price[1]+b*price[2]+c*price[3]+d*price[4]+e*price[5];
	  /* in min we keep the lowest price at which we can buy a items
	     from the 1st type, +b from the 2nd+c of the 3rd... e from the
   	      5th */

      for (int k=1;k<=s;k++) { // for each special offer
          int can=1,hm[6];
          memset(&hm,0,sizeof(hm));
          for (int l=1;l<=so[k].n;l++)
              hm[code[so[k].prod[l].id]]=so[k].prod[l].items;
             if ((hm[1]>a)||(hm[2]>b)||(hm[3]>c)||(hm[4]>d)||(hm[5]>e))
                 can=0;// we check if it is possible to use that offer

             if (can) {        // if possible-> check if it is better
                               // than the current min
                 int pr=so[k].price+sol[a-hm[1]][b-hm[2]][c-hm[3]]
                          [d-hm[4]][e-hm[5]];
                         /* Those which are not included in the special offer */
                 if (pr<min) min=pr;
             }
      }
      sol[a][b][c][d][e]=min;

                        }
}

int main() {
    memset(&so,0,sizeof(so));
    init();
    solve();
    fout<<sol[many[1]][many[2]][many[3]][many[4]][many[5]]<<endl;
    return 0;
}

 

 

USACO section 3.4 Closed Fences(计算几何+叉积+二分) Closed Fences A closed fence in the plane is a set of non-crossing, connected line segments with N corners (3 i, yi}, i in (1..N). Every pair of adjacent vertices defines a side of the fence. 阅读详情

相关推荐

基于立创EDA的8口全千兆POE交换机设计详解:RTL8370N芯片与90W大功率供电方案

本文详细解析了基于立创EDA设计的8口全千兆POE交换机方案,核心采用RTL8370N交换芯片与支持90W大功率供电的IEEE 802.3bt标准PD芯片。文章深入探讨了PSE/PD供电管理、电源架构设计、电路细节及关键散热方案,为DIY或学习POE交换机硬件设计提供了完整的开源实践指南。

weixin_29050829的博客 1万+

USACO 3.3 Shopping Offers (shopping)

/* Main idear DP problem. Take each offer as a single choise for DP. dp[a1][a2][a3][a4][a5] = min{dp[a1-prodcut_num[i][1]][a2-prodcut_num[i][2]] [a1-prodcut_num[i][3]][a1-prodc

Hello World! 1528

RIGOL DS1102E示波器新手必看:从开机到捕获第一个波形的5分钟指南

本文为RIGOL DS1102E示波器新手提供了一份快速上手指南。内容涵盖从开机、探头校准到捕获第一个波形的完整流程,重点解析了触发设置、自动测量等核心操作,并指出了探头衰减比设置等常见误区,帮助用户快速掌握这款经典数字示波器的基本使用方法。

dream的博客 767

POJ1170 Shopping Offers(五维背包or状压dp)

Description In a shop each kind of product has a price. For example, the price of a flower is 2 ICU (Informatics Currency Units) and the price of a vase is 5 ICU. In order to attract more customer...

邵光亮的博客 872

苍穹外卖-day07 - 缓存菜品- 缓存套餐- 添加购物车- 查看购物车- 清空购物车

苍穹外卖-day07 - 缓存菜品- 缓存套餐- 添加购物车- 查看购物车- 清空购物车

ros275229的博客 1224

保姆级教程:在RK3568上搞定PR2100K+GC2385双摄(从DTS配置到HAL层补丁)

本文详细介绍了在RK3568平台上调试PR2100K+GC2385双摄系统的完整流程,从DTS配置到HAL层补丁。涵盖硬件连接、媒体控制器拓扑验证、Camera3配置、HAL层特殊补丁及性能优化等关键步骤,帮助开发者快速解决双摄调试中的常见问题,提升嵌入式视觉系统开发效率。

weixin_28724661的博客 201

USACO 3.3 Shopping Offers

后边动规没有优化,偷懒了。。。 TASK: shoppingLANG: C++Compiling...Compile: OKExecuting... Test 1: TEST OK [0.000 secs, 3060 KB] Test 2: TEST OK [0.000 secs, 3060 KB] Test 3: TEST OK [0.000 secs, 3060 K...

weixin_30768175的博客 114

图解基站机房:AAU、RRU与BBU之间的线缆连接与规格选择

本文以图解方式详解了5G基站机房中AAU、RRU与BBU三大核心设备之间的线缆连接方案与规格选择。重点阐述了电力线(如2×10 mm²直流电缆)、数据光缆(如野战光缆与波分复用)及射频馈线的功能、选型标准与实战布线法则,为通信工程部署与维护提供清晰指导。

weixin_29306011的博客 543

USACO 3.3.2 Shopping Offers解题报告

写在前面:因为之前没写的C++的USACO Training的解题报告太多……所以就不写了,要是想要代码可以联系我:xiedong_1993@foxmail.com 这题就是传说中的五维背包,其实写起来难度不大。但是我写的时候可以说是遇到了重重困难。因为我对C++的掌握还不如Pascal,所以很多东西写的不是很熟。这题有一个很大的问题就在于,最后有用的只有五种物品,但是物品的编号却又很...

diekang6987的博客 272

PoE 的三大国际标准:PoE、PoE+、PoE++

很多人知道 PoE 能“一根网线,既供电又传数据”,但鲜少有人能说清楚:PoE 供电到底分几种标准?差别有多大?哪些设备要用 PoE,哪些必须上 PoE+ 或 PoE++?今天,我们就来一次彻底的“拆解”,把 PoE 的三大国际标准——讲得明明白白,顺便也帮你厘清网络工程中的常见“供电疑惑”。

网络技术联盟站 1568

ComfyUI 本地部署指南:概念、部署过程、生成图片、共享 WebUI 模型

ComfyUI 是一个基于节点的 Stable Diffusion 图形化用户界面。您可以通过将不同的节点连接在一起来构建生成图像的工作流程。一些常用的节点包括加载检查点模型(Load Checkpoint)、输入提示词(CLIP Text Encode)、指定采样器(KSampler)等。ComfyUI 将工作流程分解为可重新排列的元素,以便您可以轻松创建自己的元素。

水滴的博客 5048

USACO Training Section 3.3 Shopping Offers

[url="http://ace.delos.com/usacoprob2?a=vKbrJN28FC9&S=shopping"]英文原题[/url] [url="http://www.wzoi.org/usaco/14%5C307.asp"]中文题译[/url] [size=small]这是个与日常生活相关的题。商场促销,把许多商品捆绑销售并优惠价格,一个精明的先生拿着老婆给的购物清...

山中竹笋 213

高项备考论文:规划绩效域

高项备考论文:规划绩效域

liuxu324的博客 1140

USACO Training Section 3.3 Shopping Offers

拿给出的每种方案作为一种物品其他的单卖的物品也作为一种物品 拿它们去跑背包就行 注意编号对应上就行 代码: #include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <cctype> ...

weixin_30648963的博客 174

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

POJ 1170 Shopping Offers (状压DP)

首先确定dp的状态是购买当前这些物品所需要的最小价值,显然对于每个打折方案,都可以到达一个其他状态,也当前物品就是加上那个方案新买的物品,并获得一个新价值。用这个新价值去更新新状态,就是一个典型的完全背包。 剩下的就是找到一个方法来表示每个状态。因为每种物品最多5个,所以想到用6进制来状压(注意可能的数量是0~5,6种情况,不是5种)。最多5种物品,因此状态数最多6^5。 代码: #

Baoli1008的专栏 913

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Shopping Offers 状态压缩DP+背包

思路:一种商品最多能买5个所以可以用六进制数表示 状态压缩DP 转化成背包问题  一种组合看作一个新的类型的物品#include&lt;cstdio&gt; #include&lt;iostream&gt; #include&lt;algorithm&gt; #include&lt;cstring&gt; #define inf 0x3f3f3f3f3f using namespace std; ...

Bug___Maker的博客 237

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

usaco shopping offers 解析 and C 语言实现

题意:现在商场正在打折,打折的方式是同时买规定的的物品会比分开买便宜,现在告诉你打折的方式和要买的物品,求最少的钱,有个条件是不可以多买物品。 本题是典型的动态规划,对于动态规划问题,关键是找出其最优子结构,然后写出其递归式,然后,填表及可,另外注意各种边界条件。 对于本题,递归式可写为:  d[a1][a2][a3][a4][a5]=min(d[a1][a2][

张某人ER的技术博客 ==学习&&分享== 760

USACO Shopping Offers 解题报告

这道题刚开始用搜索做的,即遍历每种特惠的可能次数,最后取最省的组合。虽然用到了剪枝(当当前的费用已经超过了当前最省的组合,就不必接着考虑后面的特惠了),但是仍然效率特别低,在遇到后面的测试点的时候程序就无止境地跑下去了。 后来看到网上说用动态规划,因为最多只有5种商品,每种商品最多买5个,所以状态总数特别少,只有6^5=7776。所以用动态规划把表填了就好。 简单总结: 1.每次做题对状态总

thestoryofsnow的专栏 1645

USACO Shopping Offers

状态压缩,因为每个物品最多只有5个,直接十进制

jinjiahao5299的专栏 495

USACO section 3.1 Contact(AC自动机)

Contact IOI'98 The cows have developed a new interest in scanning the universe outside their farm with radiotelescopes. Recently, they noticed a very curious microwave pulsing emission sent right f

nealgavin的专栏 9384

USCAO section 1.3 Calf Flac

Calf Flac It is said that if you give an infinite number of cows an infinite number of heavy-duty laptops (with very large keys), that they will ultimately produce all the world's great palindromes

nealgavin的专栏 6656

USACO section 1.5 Checker Challenge(dfs深搜)

Checker ChallengeExamine the 6x6 checkerboard below and note that the six checkers are arranged on the board so that one and only one is placed in each row and each column, and there is never more tha

nealgavin的专栏 1924

USACO section 2.3 Longest Prefix(dp)

Longest Prefix IOI'96 The structure of some biological objects is represented by the sequence of their constituents, where each part is denote by an uppercase letter. Biologists are interested in

nealgavin的专栏 1487

USACO section 2.4 Cow Tours(并查集+最短路)

Cow Tours Farmer John has a number of pastures on his farm. Cow paths connect some pastures with certain other pastures, forming a field. But, at the present time, you can find at least two pasture

nealgavin的专栏 1406
上一篇: ZOJ 1011 NTA(二叉树+vector)
下一篇: hdu 1007 Quoit Design(平面最近点对)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址