[DP] Jzoj 5907 Qinggong

Source: Internet
Author: User

Description Topic Background:
The venerable deity has entered the world of Motomi, and as an MMORPG is essential for doing tasks, but running maps is very unpleasant. Fortunately, the base three can use Qinggong, but the holiness of God up some hand remnants, he decided to use quincuncial pile practice qinggong.
Title Description:
There are a total of n stakes, the requirements from the beginning (0), through all quincuncial pile, just to reach the end of N, the deity of God up to a total of K-type Gate faction of the Qinggong, different gate qinggong through the quincuncial pile number of different, spending time is different. But the venerable deity can only use one qinggong at a time, and when he uses other Qinggong, it takes a W-second switch (it can start with any gate and does not need a replacement time). As the venerable God is as high as a hand, he cannot use some of the qinggong of the quincuncial pile, including the starting and ending points. The Venerable God Gundam wants to know how soon he can reach the finish line. If no solution is output-1. Input First line n,k,w
Next K-line, each behavior AI and WI represents the I-type Qinggong spends vi seconds passing AI Stakes.
The next line of Q is the limit number.
Next Q line, each action Xi and Ki on behalf of the first XI Quincuncial pile cannot use the qinggong of the first Ki type gate. The output row answer is the shortest time required. Sample Input
Sample input1:6 2 1021 1Sample input2:6 2 51 13 100
Sample Output
Sample Output1:18 Sample Explanation 1: First use the second Qinggong to spend 10 seconds to 3, then 5 seconds to switch to the first Qinggong, and then 3 seconds to 6. Altogether spent 10+5+3=18 seconds sample Output2:6 Sample explanation 2: Directly spent 6 seconds to 6;
Data constraint20% n<=20,k<=10,q<=200;
For another 20% of the data w=0
For another 20% of the data q=0
So the data satisfies n<=500,k<=100,q<=50000,vi<=1e7;
Ensure data is valid HINTQ: May I ask the first question to jump back?
A: Not allowed

Analysis

This simple DP, the key is how to judge Qinggong in this section is available

Build a h[i][j] indicates the number of times that J's work method was disabled (that is, prefix and), from the starting point to the first

And then minus 0, you can move.

#include <iostream>#include<cstdio>#include<memory.h>using namespaceStd;typedefLong Longll;Const intn=5e2+Ten;Const intk=1e2+Ten; ll W[k],a[k];intn,k,q;ll w;ll f[n][k];intH[n][k];intMain () {Freopen ("qinggong.in","R", stdin); Freopen ("Qinggong.out","W", stdout); scanf ("%d%d%lld",&n,&k,&W);  for(intI=1; i<=k;i++) scanf ("%lld%lld",&a[i],&W[i]); scanf ("%d",&q);  for(intI=1; i<=q;i++) {        intb; scanf ("%d%d",&a,&b); H[A][B]=1; }     for(intI=1; i<=n;i++)         for(intj=1; j<=k;j++) H[i][j]+=h[i-1][j];  for(intI=1; i<=n;i++)         for(intj=1; j<=k;j++) F[i][j]=1ll<< +;  for(intI=1; i<=n;i++)         for(intj=1; j<=k;j++)             for(intL=1; l<=k;l++)                if(i-a[l]>=0&&h[i][l]-h[i-a[l]][l]==0&&f[i-a[l]][j]!=1ll<< +) F[i][l]=min (f[i][l],f[i-a[l]][j]+w[l]+ (j==l?0: W)); ll ans=1ll<< +;  for(intI=1; i<=k;i++) ans=min (ans,f[n][i]); printf ("%lld",ans==1ll<< +?-1: ans); Fclose (stdin); fclose (stdout);} 
View Code

[DP] Jzoj 5907 Qinggong

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.