10898 - Combo Deal
Moderator: Board moderators
10898 - Combo Deal
im getting TLE
my algo is as follows:
#assume in each case there are 6 items in combos. if a combo has less than 6 items then the remainings are 0. for example a combo with 3 items:
2 1 2 455
will be treated as
2 1 2 0 0 0 455
#treat each individual item as combo item. if item 1 costs 100 cents then treat it as
1 0 0 0 0 0 100
if item 3 costs 400 cents then treat it as
0 0 1 0 0 0 400
and so on....
#then i used a table with 6 dimension tab[10][10][10][10][10][10] and done something like "coin change" (0/1 knapsack)
this algo is of O(N^6)*(individuals + combos) ,N=10 and generates TLE. how its possible to solv it 00.000 sec....plz help
my algo is as follows:
#assume in each case there are 6 items in combos. if a combo has less than 6 items then the remainings are 0. for example a combo with 3 items:
2 1 2 455
will be treated as
2 1 2 0 0 0 455
#treat each individual item as combo item. if item 1 costs 100 cents then treat it as
1 0 0 0 0 0 100
if item 3 costs 400 cents then treat it as
0 0 1 0 0 0 400
and so on....
#then i used a table with 6 dimension tab[10][10][10][10][10][10] and done something like "coin change" (0/1 knapsack)
this algo is of O(N^6)*(individuals + combos) ,N=10 and generates TLE. how its possible to solv it 00.000 sec....plz help
algo
your algorithm and coding-technique is exact equal to mine.
i used also table[10][10][10][10][10][10], and dynamic programming
but my algorithm gots AC in 2.568 sec
so, if your source code is right, i think you won't got TLE.
however, the access like
a[1][3][2][6][4][0]
is too slow :
a[132640] is more faster.
we can convert item's stat into 6-digited integer number;
i think (yet i didn't write code with this method) it will be more faster.
i used also table[10][10][10][10][10][10], and dynamic programming
but my algorithm gots AC in 2.568 sec
so, if your source code is right, i think you won't got TLE.
however, the access like
a[1][3][2][6][4][0]
is too slow :
a[132640] is more faster.
we can convert item's stat into 6-digited integer number;
i think (yet i didn't write code with this method) it will be more faster.
Sorry For My Poor English.. ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
Hi,
During contest I used the same algo as yours. This gave me Accepted in 0.8 sec, slightly less than the 1-second time limit.
Now I recoded my program and get Accepted in 0.03 sec. In my new program I used top-down approach, since it's obviously faster under the problem constraints. Think about that.
Btw, I think this line in prob description might also give you some idea to optimize your program:
P.S. For those whose runtime exceeds 1 second (time limit during contest), please consider revising your code. It will get TLE during actual contest......
During contest I used the same algo as yours. This gave me Accepted in 0.8 sec, slightly less than the 1-second time limit.
Now I recoded my program and get Accepted in 0.03 sec. In my new program I used top-down approach, since it's obviously faster under the problem constraints. Think about that.
![:wink:](./images/smilies/icon_wink.gif)
Btw, I think this line in prob description might also give you some idea to optimize your program:
Have fun~~Buying a combo is cheaper than buying its items individually.
P.S. For those whose runtime exceeds 1 second (time limit during contest), please consider revising your code. It will get TLE during actual contest......
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
-
- Guru
- Posts: 647
- Joined: Wed Jun 26, 2002 10:12 pm
- Location: Hong Kong and New York City
- Contact:
I did it naively memoization like you described and it runs in 0.5 seconds. I don't clear values for each query, only for each different set..
Check out http://www.algorithmist.com !
I don't really think this is a hard problem. I've tried both bottom-up approach and memoization but the result is the same - WA. I just don't see the reason why.. Is there any tricky input?
Here's my source: a straightforward memoization
Here's my source: a straightforward memoization
Code: Select all
cut after AC
Last edited by tRipper on Mon Sep 26, 2005 9:03 pm, edited 1 time in total.
If I am out of my mind, it's all right with me.
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
Re: 10898 - Combo Deal
What is the recommended way to scan doubles and typecast to int?
For example, if I'm reading 9.14, and I want it to be 914, I would do: scan as double, multiply that double by 100, then typecast to int.
For this problem, I think one can do "%d.%d" to be safe, but I was wondering if the above approach is safe, precision-wise.
EDIT: This problem already gives it in cents, so I don't need to do the conversion. Still wondering what the safe way is, though.
For example, if I'm reading 9.14, and I want it to be 914, I would do: scan as double, multiply that double by 100, then typecast to int.
Code: Select all
double f;
cin >> f;
f*=100;
int i = (int) f;
EDIT: This problem already gives it in cents, so I don't need to do the conversion. Still wondering what the safe way is, though.