Single Round Match 728 Round 1 - Division II, Level Two

本文详细解析了编程竞赛Single Round Match 728第二阶段的题目,涵盖了算法思路、解题策略和实战技巧,旨在帮助参赛者提升编程解决问题的能力。
摘要由CSDN通过智能技术生成

Problem Statement for IncreasingSequencesEasy

Problem Statement

 

You are given two int[]s L and R, each of length n.

Find the number of strictly increasing sequences of integers A[0] < A[1] < ... < A[n-1] such that L[i] ≤ A[i] ≤ R[i] for every i. Return this number modulo 998244353.

 

Definition

 
Class: IncreasingSequencesEasy
Method: count
Parameters: int[], int[]
Returns: int
Method signature: int count(int[] L, int[] R)
(be sure your method is public)
 
 
 

Notes

- The number 998244353 is a prime number.
 

Constraints

- n will be between 1 and 300, inclusive.
- L will contain exactly n elements.
- R will contain exactly n elements.
- L[i] will be between 1 and 104, inclusive.
- R[i] will be between L[i] and 104, inclusive.
 

Examples

0)  
 
{1, 3, 1, 4}
{6, 5, 4, 6}
Returns: 4
There are 4 strictly increasing sequences satisfying the conditions: {1, 3, 4, 5}, {1, 3, 4, 6}, {2, 3, 4, 5} and {2, 3, 4, 6}.
1)  
 
{10, 20}
{20, 30}
Returns: 120
2)  
 
{20, 10}
{30, 20}
Returns: 0
3)  
 
{4, 46, 46, 35, 20, 77, 20}
{41, 65, 84, 90, 49, 86, 88}
Returns: 2470
4)  
 
{1, 1, 1}
{10000, 10000, 10000}
Returns: 908107402
Don't forget about the modulo.

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.

This problem was used for: 
       Single Round Match 728 Round 1 - Division II, Level Two

//SRM728 Round 1 - Division II, Level Two
import java.util.Scanner;

public class Main {
    public static int n;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

			//int n=sc.nextInt();
		 n=sc.nextInt();
		int []s=new int[n];
		int []t=new int[n];
		for(int i=0;i<n;i++)
		{
			s[i]=sc.nextInt();
			
		}
		for(int i=0;i<n;i++)
		{
			t[i]=sc.nextInt();
		}
		int ans=count(s,t);
		System.out.println(ans);
	}
	public static int count(int []L,int[] R)
	{
		int mod=998244353;
		int n=L.length;
		int [][]dp=new int[n][10010];
		int s=0;
		for(int i=L[0];i<=R[0];i++)
			dp[0][i]=1;
		for(int i=1;i<n;i++) {
			int []sum=new int[10010];
			for(int j=L[i-1];j<=R[i];j++) {
				sum[j]=sum[j-1]+dp[i-1][j];
				sum[j]%=mod;
			}
			//System.out.println(sum[R[i]);
			for(int j=L[i];j<=R[i];j++) {
				dp[i][j]+=sum[j-1];
				/*if(L[i]-1>=0)
					dp[i][j]-=sum[L[i]-1];*/
				dp[i][j]%=mod;
			}
		}
		for(int i=L[n-1];i<=R[n-1];i++) {
			s+=dp[n-1][i];
			s%=mod;
		}
		return s;
    }
}
#include<iostream>  
#include<cstdio>  
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int>pii;
int dp[200][10005];
int mod = 998244353;
class IncreasingSequencesEasy
{
public:
	int count(vector<int>L, vector<int>R)
	{
		int n = L.size();
		for (int i = L[0]; i <= R[0]; i++)
			dp[0][i] = 1 + dp[0][i - 1];
		for (int j = R[0] + 1; j < 10001; j++)
			dp[0][j] = dp[0][j - 1];
		for (int i = 1; i < n; i++)
		{
			for (int j = L[i]; j <= R[i]; j++)
				dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1]) % mod;
			for (int j = R[i] + 1; j < 10001; j++)
				dp[i][j] = dp[i][j - 1];
		}
		return dp[n - 1][R[n - 1]];
	}
};



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值