2287:POJ Challenge Vanishing Thing

Source: Internet
Author: User

Topic links

The main topic: Ftiasch has N items, volume is W1, W2, ..., WN. As a result of her negligence, article I was lost. "There are several ways to use the rest of the N-1 to fill an X-volume backpack. "– This is a classic question. She recorded the answer as count (i, x), want to get all 1 <= i <= N, 1 <= x <= m of Count (i, X) table

Solution: F[x] f[x] represents the number of scenarios that happen to be filled with X-volume, this 01 backpack

Consider the case of the optional item I below
G[X] is the number of solutions that do not select the current item I exactly fill the X volume

Then sort the discussion
1. x<w[i] x g[x]=f[x]
2. x≥w[i] x \geq w[i) equals the total scheme minus the number of scenarios selected for I

So how do I get the number of options for the current item I just fill the x volume?

You can divide this into two steps: Do not select the current item I exactly fill x-w[i] Volume Select current Item I

IE G[x]=f[x]-g[x-w[i]]

My harvest: a special posture

 #include <bits/stdc++.h> using namespace std;  
int n,m;
int w[2010];  

Long Long f[2010],g[2010];
    void ZeroOne () {f[0]=1;
for (int i=1;i<=n;i++) for (int j=m;j>=w[i];j--) f[j]= (F[j]+f[j-w[i]])%10;
        } void Calc () {for (int. i=1;i<=n;i++) {for (int j=0;j<w[i];j++) G[J]=F[J];
        for (int j=w[i];j<=m;j++) g[j]= (f[j]-g[j-w[i]]+10)%10;
        for (int j=1;j<=m;j++) printf ("%d", g[j]);
    Putchar (' \ n ');
    }} void Work () {ZeroOne ();
Calc ();
    } void Init () {scanf ("%d%d", &n,&m);
for (int i=1;i<=n;i++) scanf ("%d", &w[i]);
    } int main () {init ();
    Work ();  
return 0; }

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.