NYOJ 708 ones(try again)
시간 제한:
1000ms | 메모리 제한:
65535 KB
난이도:
3
묘사
Given a positive integer N (0<=N<=10000), you are to find an expression equals to N using only 1,+,*,(,). 1 should not appear continuously, i.e. 11+1 is not allowed.
입력
There are multiple test cases. Each case contains only one line containing a integer N
출력
For each case, output the minimal number of 1s you need to get N.
샘플 입력
2
10
샘플 출력
2
7
//최우수 서브 구조는 21 호출 3*7 시 7이 이미 최우수 상태이고 직접 호출하는 것이다
//완전히 이해한 것은 아니다
#include
#include
#include
#include
using namespace std;
int dp[10010]={0};
int main()
{
dp[1]=1;
for(int i=2; i<10010; i++)
{
dp[i]=dp[i-1]+1;
for(int j=i-1; j>=1; j--)
{
if(i%j==0)
{
dp[i]=min(dp[i],dp[j]+dp[i/j]);
}
}
}
int n;
while(~scanf("%d",&n))
{
printf("%d
",dp[n]);
}
return 0;
} //ac
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
01 가방, 완전 가방, 다중 가방 dp(동적 기획 입문 dp)01 가방은 2진법으로 직접 표시할 수 있지만 데이터 양이 너무 많으면 시간을 초과하는 것이 폭력이다.01 가방의 사상은 바로 이 물품에 대해 내가 넣은 가치가 큰지 안 넣은 가치가 큰지 비교하여 방정식 f[i][v...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.