Bnu oj 1027 gold coin system

Source: Internet
Author: User

Gold Coin System

Time limit:1000 ms Memory limit:65535kb 64-bit integer Io format: % LLDJava class name: Main

YC has been back in Hangzhou, and I like to make some changes to buy equipment. After a week of hard work, I finally streaked naked into the e. -_-
He suffered a lot during the stall, for example, there was no change or anything. In this way, if someone comes to buy things, he will make the price because he cannot get the money. Therefore, he hopes to know how many methods can be used to obtain a certain nominal value. For example, a 15-piece nominal value can be composed of two seven-dollar nominal values and one-dollar nominal value. In this way, it is easier for him to find change for items priced as one item.
In order to clarify the intention of the subject, let's take another example. The current currency system has the following denominations: 1, 2, 5, and 10. In this way, the price of 18 yuan can be 18x (1 yuan), 9x (2 yuan), 8x (2 yuan) + 2x (1 yuan), 3x (5 yuan) + 1x (2 RMB) + 1x (1 RMB), etc.
Your task is to assign a nominal value to the coin VI, which has an infinite number of coins and determine the price of N.

 

Input

The first behavior is a number z, indicating that there are Z group test data.
Each group of test data is composed of two rows,
The first behavior is two numbers V, N. There are V (1 <= V <= 25) coins, and the price N (1 <= n <= 10,000) to be expressed ).
Number of values in the second line, separated by spaces. Each number VI represents an existing coin face value.

 

Output

Each group of test data has a row of output, including a number. The value of N is represented in P notation in a gold coin system consisting of VI.

Sample Input
13 101 2 5
Sample output
10
Hint

The data volume may be large to ensure that long does not overflow.

Source, the third session of the 7 Beijing Normal University Program Design Competition, authorxsugarx: DP...
 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <climits> 7 #include <algorithm> 8 #include <cmath> 9 #define LL long long10 using namespace std;11 LL dp[10010],d[30];12 int main(){13     int i,kase,n,v,j;14     scanf("%d",&kase);15     while(kase--){16         scanf("%d %d",&n,&v);17         for(i = 0; i < n; i++)18             scanf("%lld",d+i);19         memset(dp,0,sizeof(dp));20         dp[0] = 1;21         for(i = 0; i < n; i++){22             for(j = 0; j+d[i] <= v; j++){23                 dp[j+d[i]] += dp[j];24             }25         }26         printf("%lld\n",dp[v]);27     }28     return 0;29 }
View code

 

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.