刚学的c#(没学完),有没有大佬教教,为什么re了
查看原帖
刚学的c#(没学完),有没有大佬教教,为什么re了
92605
runtime_error楼主2023/3/24 22:23

背包思想,re了

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace HelloWprld
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string[] inputNM = Console.ReadLine().Split(' ');
            int n = int.Parse(inputNM[0]);
            int m = int.Parse(inputNM[1]);
            int[] a = new int[n+1];
            int[] bag = new int[m+10];
            bag[0] = 1;
             string[] inputA = Console.ReadLine().Split(' ');
            for (int i = 1; i <= n; i++)
            {
                a[i] = int.Parse(inputA[i-1]);
            }
            for(int i = 1; i <= n; i++)
            {
                for(int j = m; j >= a[i]; j--)
                {
                    bag[j] += bag[j - a[i]];
                }
            }
            Console.WriteLine(bag[m]);
            //Console.Read();
        }
    }
}

2023/3/24 22:23
加载中...