China Merchants Bank Fintec training Camp Programming questions __ Written examination

Source: Internet
Author: User
I. Total currency exchange
public static void Main (string[] args) {
    Scanner in = new Scanner (system.in);
    int t = In.nextint ();
    while (t--> 0) {
        int N = In.nextint ();
        int K = In.nextint ();
        int[] coins = new Int[n];
        for (int i = 0; i < N; i++) {
            Coins[i] = In.nextint ();
        }
        Int[][] dp = new INT[N][K + 1];
        for (int i = 0; i < N; i++) {
            dp[i][0] = 1;
        }
        for (int i = 0; I <= K; i++) {
            if (i% coins[0] = = 0) {
                dp[0][i] = 1;
            }
        }
        for (int i = 1; i < N; i++) {for
            (int j = 0; J <= K; j) {
                dp[i][j] = dp[i-1][j];
                if (J >= Coins[i]) {
                    Dp[i][j] = = Dp[i][j-coins[i]]
                ;
                DP[I][J]%= 100000007
            }
        }
        System.out.println (Dp[n-1][k]);
    }
second, the calf to send grass
private static int[] DP;

public static void Main (string[] args) {
    Scanner in = new Scanner (system.in);
    int t = In.nextint ();
    while (t--> 0) {
        int N = In.nextint ();
        DP = new Int[n];
        Int[] values = new Int[n];
        for (int i = 0; i < N; i++) {
            Values[i] = In.nextint ();
        }
        System.out.println (Math.max (Sell (values, 0, N-2), Sell (values, 1, N-1));

    }

private static int sell (int[] values, int A, last) {
    if (Last-first = 0) return Values[first];
    if (Last-first = = 1) return Math.max (Values[first], values[last]);
    Dp[first] = Values[first];
    Dp[first + 1] = Values[first + 1];
    Dp[first + 2] = Values[first] + Values[first + 2];
    for (int i = i = 3; I <= last; i++) {
        Dp[i] = Math.max (dp[i-2), dp[i-3]) + values[i];
    Return Math.max (Dp[last], dp[last-1]);
}

Reference links

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.