結果

問題 No.1111 コード進行
ユーザー umezo
提出日時 2020-07-10 23:11:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 830 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 196,704 KB
最終ジャッジ日時 2025-01-11 19:12:03
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:42:13: warning: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
   42 |     ans=(ans+dp[n][j][K])%MOD;
      |         ~~~~^~~~~~~~~~~~~
main.cpp:40:6: note: ‘ans’ was declared here
   40 |   ll ans;
      |      ^~~

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const ll MOD=1e9+7;

int main(){
  ll n,m,K;
  cin>>n>>m>>K;
  
  ll dp[n+1][301][K+1];
  rep(i,n+1){
    rep(j,301){
      rep(k,K+1) dp[i][j][k]=0;
    }
  }
    
  vector<pair<ll,ll>> A[301];
  ll p,q,c;
  rep(i,m){
    cin>>p>>q>>c;
    A[p].push_back({q,c});
    dp[2][q][c]++;
  } 
  
  for(int i=2;i<=n-1;i++){
    for(int j=1;j<=300;j++){
      for(int k=0;k<=K;k++){
        for(auto x:A[j]){
          if(k+x.second>K) continue;
          dp[i+1][x.first][k+x.second]=(dp[i+1][x.first][k+x.second]+dp[i][j][k])%MOD;
        }
      }
    }
  }
        
  ll ans;
  for(int j=1;j<=300;j++){
    ans=(ans+dp[n][j][K])%MOD;
  }
  
  cout<<ans<<endl;
  
  return 0;
}
0