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. 阅读详情

相关推荐

避开这些坑!用Python ReportLab生成PDF时字体处理与中文排版的5个关键技巧

本文针对Python ReportLab库在PDF自动化生成中常见的中文排版难题,提供了五个关键技巧。内容涵盖字体注册的稳健策略、段落样式的精细控制、表格内中文的换行对齐、页面布局管理以及性能优化,旨在帮助开发者彻底解决中文乱码、排版错位等问题,生成专业美观的PDF文档。

weixin_29250403的博客 630

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

松材线虫病害智能检测:基于YOLOv8的无人机航拍数据集构建与模型优化

本文探讨了基于YOLOv8的无人机航拍技术在松材线虫病害智能检测中的应用。通过构建高质量巡检数据集和优化模型架构(如RepVit主干网络和跨尺度特征融合模块),显著提升了病害识别准确率。该方案在复杂森林环境中表现出色,将检测效率提高数倍,为林业病害防控提供了高效解决方案。

vulkan6gpu的博客 1004

USACO Shopping Offers 解题报告

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

thestoryofsnow的专栏 1644

三维重建笔记_光束平差法(Bundle Adjustment, BA)

目录 1 光束平差法(Bundle Adjustment, BA) 1.1 SFM (Structure‐from‐Motion) 定义 问题描述 1.2 重投影误差 (Reprojection Error) 目标函数 1.3 使用 Levenberg‐Marquardt Algorithm 进行优化 问题描述 简化目标函数 参考 Gauss‐Newton Method ...

惊鸿一博 2万+

Windows 11 上 WSL2 安装 Ubuntu 22.04 保姆级教程(含桌面环境配置)

本文提供在Windows 11上通过WSL2安装Ubuntu 22.04并配置桌面环境的详细教程。涵盖WSL2核心安装、性能调优、Xfce桌面环境部署以及开发环境集成,帮助开发者构建高效、无缝的Windows-Linux混合开发工作站。

Jerry的专栏 644

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

【爬虫】Python实现爬取淘宝商品信息(超详细)

项目基于Python的第三方库Selenium模拟浏览器运行、PyQuery解析和操作HTML文档,获取淘宝平台中某类商品的详细信息(商品标题、价格、销量、商铺名称、地区、商品详情页链接、商铺链接等),并基于第三方库openpyxl建立、存储于Excel表格中。# 全局变量count = 1 # 写入Excel商品计数# 启动ChromeDriver服务# 关闭自动测试状态显示 // 会导致浏览器报:请停用开发者模式# 把chrome设为selenium驱动的浏览器代理;# 窗口最大化。

qq_46315152的博客 4万+

USACO 3.3 Shopping Offers

Shopping OffersIOI'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 c...

weixin_30438813的博客 181

NVIDIA Isaac Lab 入门教程(一)

Isaac Lab 是一个用于机器人学习的统一模块化框架,旨在简化机器人研究中的常见工作流程(如 RL、从演示中学习和运动规划)。它建立在英伟达 Isaac Sim 的基础上,利用最新的仿真功能实现逼真的场景和快速高效的仿真。该框架的核心目标是Isaac Lab 的主要功能包括:由 PhysX 提供的快速准确的物理模拟、用于矢量化渲染的平铺渲染 API、用于提高鲁棒性和适应性的域随机化,以及对在云中运行的支持。有关该框架的更多信息,请参阅论文[MYY+23]。

机器人控制与仿真应用 8222

Microsemi Libero系列教程(全网首发)

关于Libero IDE和Libero SoC Libero分为Libero IDE和Libero SoC,Libero IDE最新版本是v9.2 SP3(2016年4月4日)已经不再更新维护了,而Libero SoC是Libero IDE的升级版,官方推荐的开发工具,文中的Libero指的是Libero SoC。 Libero SoC Libero® SoC是Microsemi(美高森美)官方...

whik1194的博客 2万+

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

SonarQube 完整手册(2026 最新)

摘要: SonarQube是一款静态代码分析(SAST)平台,支持20+语言(如Java/Go/Python),提供Bug、漏洞、代码异味等检测,集成DevOps流水线。其架构包含服务端、扫描器和SonarLint插件。2026年四大版本:免费社区版(基础功能)、开发者版(多分支/PR分析)、企业版(合规治理)、数据中心版(高可用集群)。核心功能包括质量门禁(QualityGate)、密钥泄露检测及六大质量指标。部署推荐Docker+PostgreSQL,扫描支持Maven/CLI方式。

SmallBull的博客 697

USACO Shopping Offers

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

jinjiahao5299的专栏 495

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

USACO Training Section 3.3 Shopping Offers

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

weixin_30648963的博客 174

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

USACO 3.3.2 Shopping Offers解题报告

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

diekang6987的博客 272

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是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的博客 236

usaco shopping offers 解析 and C 语言实现

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

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

POJ 1170 Shopping Offers (状压DP)

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

Baoli1008的专栏 913

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的专栏 1923

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、付费专栏及课程。

余额充值