Time Limit: 20 Sec Memory Limit: 256 MBios
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=116998app
To host a regional contest like NWERC a lot of preparation is necessary: organizing rooms and computers, making a good problem set, inviting contestants, designing T-shirts, booking hotel rooms and so on. I am responsible for going shopping in the supermarket.ide
When I get to the cash register, I put all my n items on the conveyor belt and wait until all the other customers in the queue in front of me are served. While waiting, I realize that this supermarket recently started to round the total price of a purchase to the nearest multiple of 10 cents (with 5 cents being rounded upwards). For example, 94 cents are rounded to 90 cents, while 95 are rounded to 100.this
It is possible to divide my purchase into groups and to pay for the parts separately. I managed to find d dividers to divide my purchase in up to d+1 groups. I wonder where to place the dividers to minimize the total cost of my purchase. As I am running out of time, I do not want to rearrange items on the belt.spa
The input consists of:
one line with two integers n (1≤n≤2000) and d (1≤d≤20), the number of items and the number of available dividers;
one line with n integers p1,… pn (1≤pi≤10000 for 1≤i≤n), the prices of the items in cents. The prices are given in the same order as the items appear on the belt.
pwa
Output the minimum amount of money needed to buy all the items, using up to d dividers.rest
5 1
13 21 55 60 42ip
190ci
題意 get
這個商店交款方式是4舍5入的,而後你能夠把你的商品分紅d堆交錢
而後問你最少交多少錢
題解:
dp題呀
就至關於有n-1個空,插d個板子
那麼咱們就能夠DP解決他,dp[i][j]表示前i個空插了j個板子後的最小值
代碼:
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 200001 #define mod 10007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; /* inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } */ inline ll read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } //************************************************************************************** int a[2010]; ll dp[2010][30]; ll cal(ll x) { if(x%10>=5) x+=10; x-=x%10; return x; } int main() { int n,d; scanf("%d%d",&n,&d); for(int i=1;i<=n;i++) a[i]=read(); for(int i=1;i<=n-1;i++) { for(int j=0;j<=d;j++) { if(j==0) dp[i][j]+=dp[i-1][j]+a[i]; else dp[i][j]=min(dp[i-1][j]+a[i],cal(dp[i-1][j-1]+a[i])); } } ll ans=inf; for(int j=0;j<=d;j++) ans=min(cal(dp[n-1][j]+a[n]),ans); cout<<ans<<endl; }