소 여객 연습 경기

4238 단어 소그물
A문제는 dp 두 번 가능하고 각각 두 가지 가격으로 nm가지 상품을 합쳐도 돼요.
#include 
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
#define sz size()
#define cl clear()
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078164
typedef long long LL;
typedef pair pr;
const int inf = 99999999;
const double eps = 1e-8;
const int dir4[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};
const int dir8[8][2] = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int maxn = 2e5 + 10;
//const int mod = 1e9 + 7;
 
int dp[1005];
int v[2005];
int main()
{
    int t;
    int n, m, k, mod;
    cin >> t;
    while(t --)
    {
        //cout << endl;
        mset(dp,0);
        dp[0] = 1; 
        cin >> n >> m >> k >> mod;
         
        for(int i = 1;i <= n;i ++)
        {
            v[i] = 1;
        }
        for(int i = n + 1;i <= n + m;i ++)
        {
            v[i] = 2;
        }
         
         
        for(int i = 1;i <= n + m;i ++)
        {
            for(int j = v[i];j <= k;j ++)
            {
                dp[j] += dp[j - v[i]];
                dp[j] %= mod;
            }  
        }
        cout << dp[k] % mod << endl;
    }
    return 0;
}

E문제 시뮬레이션
#include 
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
#define sz size()
#define cl clear()
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078164
typedef long long LL;
typedef pair pr;
const int inf = 99999999;
const double eps = 1e-8;
const int dir4[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};
const int dir8[8][2] = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;

int a[100005];
int my[3];
	
int main() 
{
    int n;
    cin >> n;
    for(int i = 0;i < n;i ++)
    {
    	cin >> a[i];
	}
	
	bool flag = true;
	
	for(int i = 0;i < n;i ++)
    {
    	if(a[i] == 25)
    	{
    		my[0] ++;
		}
		else if(a[i] == 50)
		{
			my[1] ++;
			my[0] --;
			
		}
		else
		{
			if(my[1] > 0)
			{
				my[1] --;
				my[0] --;
				my[2] ++;
			}
			else
			{
				my[0] -= 2;
			}
		}
		if(my[0] < 0 || my[1] < 0)
		{
			flag = false;
			break;
		}
	}
	
	if(flag)
	cout << "YES" << endl;
	else 
	cout << "NO" << endl;
    return 0;
}



F문제 시뮬레이션 존재 가능한 경우 금화가 남는 모든 것을 숫자가 큰 것부터 옮겨다니게 됩니다.
#include 
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
#define sz size()
#define cl clear()
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078164
typedef long long LL;
typedef pair pr;
const int inf = 99999999;
const double eps = 1e-8;
const int dir4[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};
const int dir8[8][2] = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int maxn = 2e5 + 10;
//const int mod = 1e9 + 7;

int a[10];
int n;

int main() 
{
    cin >> n;
    
    int tm = inf;
    
	for(int i = 1;i <= 9;i ++)
    {
    	cin >> a[i];
    	tm = min(tm,a[i]);
	}
	
	if(n < tm) 
	{
		cout<< -1;
		return 0;
	}
	
	int len = n / tm, r = n % tm;
	
	for(int i = 1;i <= len;i ++)
	{
		for(int j = 9;j >= 1;j --)
		{
			if(a[j] - tm <= r)
			{
				cout << j;
				r -= a[j] - tm;
				break;
			}
		}
	}
    return 0;
}

좋은 웹페이지 즐겨찾기