小V和方程 牛客 DP 整数拆分

小V和方程

在这里插入图片描述

solution

∑ i = 1 n x i = m = > ∑ i = 1 n a i 2 x = A 2 x \sum\limits_{i=1}^{n}\sqrt {x_i}=\sqrt{m}=>\sum\limits_{i=1}^{n}\sqrt {a_i^2x}=\sqrt{A^2x} i=1nxi =m =>i=1nai2x =A2x

∑ i = 1 n a i x = A x \sum\limits_{i=1}^{n}a_i\sqrt {x}=A\sqrt{x} i=1naix =Ax

∑ i = 1 n a i = A \sum\limits_{i=1}^{n}a_i=A i=1nai=A

/*SiberianSquirrel*//*CuteKiloFish*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ill = __int128;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = ll(998244353);
const ll INF = ll(1e18 + 10);
const int N = int(1e6 + 10);
const int M = int(1e3 + 10);
inline int rnd(){static int seed=2333;return seed=(((seed*666666ll+20050818)%998244353)^1000000007)%1004535809;}
template <class T> void read(T &x) {
    static char ch;static bool neg;
    for(ch=neg=0;ch<'0' || '9'<ch;neg|=ch=='-',ch=getchar());
    for(x=0;'0'<=ch && ch<='9';(x*=10)+=ch-'0',ch=getchar());
    x=neg?-x:x;
}
ll add(ll a, ll b) {return (a + b) % MOD;}
ll sub(ll a, ll b) {return (a - b + MOD) % MOD;}
ll mul(ll a, ll b) {a %= MOD; b %= MOD;return a * b % MOD;}
//VAR
int n2[M];
int dp[M][M];
// FUNCTION
void init() {
    for(int i = 0; i <= int(1e3); ++ i) n2[i] = i * i;
}
//WORK
void solve() {
    memset(dp, 0, sizeof dp);
    init();
    int n, m; cin >> n >> m;
    int temp = 1;
    for(int i = int(1e3); i >= 1; -- i) {
        if(m % n2[i] == 0) {
            m /= n2[i];
            temp *= i;
        }
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; ++ i) {
        for (int j = 0; j <= int(1e3); ++ j) {
            dp[i][j] = dp[i - 1][j];
            if(j >= i) dp[i][j] = (1ll * dp[i][j] + dp[i][j - i]) % MOD;
        }
    }
    cout << dp[n][temp] << endl;
}
//MAIN
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef ACM_LOCAL
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
    signed test_index_for_debug = 1;
    char acm_local_for_debug = 0;
    do {
        if (acm_local_for_debug == '$') exit(0);
        if (test_index_for_debug > 20)
            throw runtime_error("Check the stdin!!!");
        auto start_clock_for_debug = clock();
        solve();
        auto end_clock_for_debug = clock();
        cout << "Test " << test_index_for_debug << " successful" << endl;
        cerr << "Test " << test_index_for_debug++ << " Run Time: "
             << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
        cout << "--------------------------------------------------" << endl;
    } while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
    solve();
#endif
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值