More actions
imported>vkdnjdldnjsw No edit summary |
imported>vkdnjdldnjsw No edit summary |
||
| Line 9: | Line 9: | ||
= 코드 = | = 코드 = | ||
== 15이원준 == | == 15이원준 == | ||
=== 타임머신 === | |||
#include<iostream> | #include<iostream> | ||
#include<vector> | #include<vector> | ||
| Line 62: | Line 63: | ||
} | } | ||
} | } | ||
} | |||
=== 오르막 수 === | |||
#include<iostream> | |||
#include<cstring> | |||
using namespace std; | |||
int arr[1001][10]; | |||
int search(int num, int pri){ | |||
if(num == 1){ | |||
return 1; | |||
} | |||
if(arr[num][pri] != -1){ | |||
return arr[num][pri]; | |||
} | |||
int ans = 0; | |||
for(int i = 0; i<=pri; i++){ | |||
ans += search(num-1, i); | |||
ans %= 10007; | |||
} | |||
arr[num][pri] = ans; | |||
return ans; | |||
} | |||
int main(){ | |||
memset(arr,-1,sizeof(arr)); | |||
int n; | |||
cin >> n; | |||
int ans = 0; | |||
for(int i = 0; i<10; i++){ | |||
ans += search(n,i); | |||
ans %= 10007; | |||
} | |||
cout<< ans <<endl; | |||
} | } | ||
= 아이디어 = | = 아이디어 = | ||
Revision as of 04:12, 14 October 2016
오늘의 문제
참가자
- 15이원준
코드
15이원준
타임머신
#include<iostream>
#include<vector>
#include<utility>
using namespace std;
int d[501] = {0,};
int check[501] = {0,};
vector<vector<pair<int, int> > > vec;
int main(){
vec.resize(501);
int n,m;
cin>>n>>m;
for(int i=0; i<m; i++){
int tmp1, tmp2, tmp3;
scanf("%d %d %d", &tmp1, &tmp2, &tmp3);
vec[tmp1].push_back(make_pair(tmp2,tmp3));
}
d[1] = 0;
check[1] = 1;
bool update = true;
for(int i = 0; i<=n && update; i++){
if(i == n){
cout<<-1 <<endl;
return 0;
}
update = false;
for(int j = 1; j<=n; j++){
if(!check[j]){
continue;
}
for(auto it = vec[j].begin(); it != vec[j].end(); it++){
if( !check[it->first] || d[it->first] > d[j] + it->second){
update = true;
check[it->first] = 1;
d[it->first] = d[j] + it->second;
}
}
}
}
for(int i = 2; i<=n; i++){
if(!check[i]){
cout<<-1<<endl;
}
else{
cout<<d[i]<<endl;
}
}
}
오르막 수
#include<iostream>
#include<cstring>
using namespace std;
int arr[1001][10];
int search(int num, int pri){
if(num == 1){
return 1;
}
if(arr[num][pri] != -1){
return arr[num][pri];
}
int ans = 0;
for(int i = 0; i<=pri; i++){
ans += search(num-1, i);
ans %= 10007;
}
arr[num][pri] = ans;
return ans;
}
int main(){
memset(arr,-1,sizeof(arr));
int n;
cin >> n;
int ans = 0;
for(int i = 0; i<10; i++){
ans += search(n,i);
ans %= 10007;
}
cout<< ans <<endl;
}
아이디어
15이원준
- 벨만 포드(이하생략)